Final Work: Empirical Analysis¶

In [1]:
import pandas as pd
In [2]:
import matplotlib.pyplot as plt # Main graphical library
import seaborn as sns # More advanced graphs
In [172]:
import scipy.stats as stats
In [3]:
oecd_output_gap = pd.read_csv('EO_29052023144557432.csv')
In [4]:
oecd_output_gap.head()
Out[4]:
LOCATION Country VARIABLE Variable FREQUENCY Frequency TIME Time Unit Code Unit PowerCode Code PowerCode Reference Period Code Reference Period Value Flag Codes Flags
0 AUS Australia GAP Output gap as a percentage of potential GDP A Annual 1985 1985 PC Percentage 0 Units NaN NaN 0.876928 NaN NaN
1 AUS Australia GAP Output gap as a percentage of potential GDP A Annual 1986 1986 PC Percentage 0 Units NaN NaN -0.914835 NaN NaN
2 AUS Australia GAP Output gap as a percentage of potential GDP A Annual 1987 1987 PC Percentage 0 Units NaN NaN 0.568731 NaN NaN
3 AUS Australia GAP Output gap as a percentage of potential GDP A Annual 1988 1988 PC Percentage 0 Units NaN NaN 1.241412 NaN NaN
4 AUS Australia GAP Output gap as a percentage of potential GDP A Annual 1989 1989 PC Percentage 0 Units NaN NaN 1.966187 NaN NaN
In [5]:
oecd_output_gap.drop(columns=['LOCATION','VARIABLE','FREQUENCY','Frequency','TIME','Unit Code','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
In [6]:
us_output_gap=oecd_output_gap[oecd_output_gap['Country']=='United States']
In [7]:
us_output_gap.head()
Out[7]:
Country Variable Time Unit Value
1056 United States Output gap as a percentage of potential GDP 1985 Percentage 1.124236
1057 United States Output gap as a percentage of potential GDP 1986 Percentage 1.376948
1058 United States Output gap as a percentage of potential GDP 1987 Percentage 1.695902
1059 United States Output gap as a percentage of potential GDP 1988 Percentage 2.743002
1060 United States Output gap as a percentage of potential GDP 1989 Percentage 3.289457
In [8]:
us_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3224325462.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
In [9]:
us_output_gap.reset_index(drop=True,inplace=True)
In [10]:
us_output_gap.columns=['year','output_gap']

US Output Gap¶

In [11]:
us_output_gap.head()
Out[11]:
year output_gap
0 1985 1.124236
1 1986 1.376948
2 1987 1.695902
3 1988 2.743002
4 1989 3.289457
In [12]:
oecd_cci=pd.read_csv('MEI_CLI_29052023213313302.csv',parse_dates=['TIME'])
In [13]:
oecd_cci.head()
Out[13]:
SUBJECT Subject LOCATION Country FREQUENCY Frequency TIME Time Unit Code Unit PowerCode Code PowerCode Reference Period Code Reference Period Value Flag Codes Flags
0 CSCICP03 OECD Standardised CCI, Amplitude adjusted (Lon... AUS Australia M Monthly 1974-09-01 Sep-1974 IDX Index 0 Units NaN NaN 98.79668 NaN NaN
1 CSCICP03 OECD Standardised CCI, Amplitude adjusted (Lon... AUS Australia M Monthly 1974-10-01 Oct-1974 IDX Index 0 Units NaN NaN 98.85406 NaN NaN
2 CSCICP03 OECD Standardised CCI, Amplitude adjusted (Lon... AUS Australia M Monthly 1974-11-01 Nov-1974 IDX Index 0 Units NaN NaN 98.99237 NaN NaN
3 CSCICP03 OECD Standardised CCI, Amplitude adjusted (Lon... AUS Australia M Monthly 1974-12-01 Dec-1974 IDX Index 0 Units NaN NaN 99.31611 NaN NaN
4 CSCICP03 OECD Standardised CCI, Amplitude adjusted (Lon... AUS Australia M Monthly 1975-01-01 Jan-1975 IDX Index 0 Units NaN NaN 99.92596 NaN NaN
In [14]:
oecd_cci.drop(columns=['SUBJECT','LOCATION','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
In [15]:
oecd_cci.head()
Out[15]:
Subject Country TIME Value
0 OECD Standardised CCI, Amplitude adjusted (Lon... Australia 1974-09-01 98.79668
1 OECD Standardised CCI, Amplitude adjusted (Lon... Australia 1974-10-01 98.85406
2 OECD Standardised CCI, Amplitude adjusted (Lon... Australia 1974-11-01 98.99237
3 OECD Standardised CCI, Amplitude adjusted (Lon... Australia 1974-12-01 99.31611
4 OECD Standardised CCI, Amplitude adjusted (Lon... Australia 1975-01-01 99.92596
In [16]:
us_cci=oecd_cci[oecd_cci['Country']=='United States']
us_cci.head()
Out[16]:
Subject Country TIME Value
11858 OECD Standardised CCI, Amplitude adjusted (Lon... United States 1960-01-01 101.6451
11859 OECD Standardised CCI, Amplitude adjusted (Lon... United States 1960-02-01 101.3811
11860 OECD Standardised CCI, Amplitude adjusted (Lon... United States 1960-03-01 101.1530
11861 OECD Standardised CCI, Amplitude adjusted (Lon... United States 1960-04-01 101.0272
11862 OECD Standardised CCI, Amplitude adjusted (Lon... United States 1960-05-01 101.0589
In [17]:
us_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/4083906159.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_cci.drop(columns=['Country','Subject'],inplace=True)
In [18]:
us_cci.reset_index(drop=True,inplace=True)
In [19]:
us_cci.head()
Out[19]:
TIME Value
0 1960-01-01 101.6451
1 1960-02-01 101.3811
2 1960-03-01 101.1530
3 1960-04-01 101.0272
4 1960-05-01 101.0589

US Monthly CCI¶

In [20]:
us_cci.columns=['month','cci']
us_cci.head()
Out[20]:
month cci
0 1960-01-01 101.6451
1 1960-02-01 101.3811
2 1960-03-01 101.1530
3 1960-04-01 101.0272
4 1960-05-01 101.0589
In [21]:
us_cci_year=us_cci.resample('Y',on='month').mean().reset_index()
In [22]:
us_cci_year['year'] = us_cci_year['month'].dt.year
In [23]:
us_cci_year.head()
Out[23]:
month cci year
0 1960-12-31 101.013275 1960
1 1961-12-31 101.056775 1961
2 1962-12-31 101.114400 1962
3 1963-12-31 101.116525 1963
4 1964-12-31 101.656658 1964
In [24]:
us_cci_year[us_cci_year['year']>1984]
Out[24]:
month cci year
25 1985-12-31 100.850008 1985
26 1986-12-31 101.051883 1986
27 1987-12-31 100.564608 1987
28 1988-12-31 100.930058 1988
29 1989-12-31 100.791175 1989
30 1990-12-31 99.454773 1990
31 1991-12-31 98.972317 1991
32 1992-12-31 98.924284 1992
33 1993-12-31 99.632367 1993
34 1994-12-31 100.740667 1994
35 1995-12-31 100.729008 1995
36 1996-12-31 100.912258 1996
37 1997-12-31 102.086683 1997
38 1998-12-31 102.234242 1998
39 1999-12-31 102.393742 1999
40 2000-12-31 102.562908 2000
41 2001-12-31 100.404999 2001
42 2002-12-31 100.396385 2002
43 2003-12-31 100.235702 2003
44 2004-12-31 101.069433 2004
45 2005-12-31 100.299339 2005
46 2006-12-31 100.164591 2006
47 2007-12-31 99.946445 2007
48 2008-12-31 97.290395 2008
49 2009-12-31 97.612842 2009
50 2010-12-31 98.276032 2010
51 2011-12-31 97.753128 2011
52 2012-12-31 98.837075 2012
53 2013-12-31 99.171598 2013
54 2014-12-31 99.773988 2014
55 2015-12-31 100.814817 2015
56 2016-12-31 100.696808 2016
57 2017-12-31 101.292675 2017
58 2018-12-31 101.461050 2018
59 2019-12-31 101.237067 2019
60 2020-12-31 99.426038 2020
61 2021-12-31 98.985485 2021
62 2022-12-31 96.753597 2022
63 2023-12-31 97.320080 2023
In [206]:
us_cci_year.drop(columns='month',inplace=True)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/937176710.py in <module>
----> 1 us_cci_year.drop(columns='month',inplace=True)
      2 us_cci_year[['year', 'cci']]

~/opt/anaconda3/lib/python3.9/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    309                     stacklevel=stacklevel,
    310                 )
--> 311             return func(*args, **kwargs)
    312 
    313         return wrapper

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   4955                 weight  1.0     0.8
   4956         """
-> 4957         return super().drop(
   4958             labels=labels,
   4959             axis=axis,

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   4265         for axis, labels in axes.items():
   4266             if labels is not None:
-> 4267                 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
   4268 
   4269         if inplace:

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors, consolidate, only_slice)
   4309                 new_axis = axis.drop(labels, level=level, errors=errors)
   4310             else:
-> 4311                 new_axis = axis.drop(labels, errors=errors)
   4312             indexer = axis.get_indexer(new_axis)
   4313 

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/base.py in drop(self, labels, errors)
   6659         if mask.any():
   6660             if errors != "ignore":
-> 6661                 raise KeyError(f"{list(labels[mask])} not found in axis")
   6662             indexer = indexer[~mask]
   6663         return self.delete(indexer)

KeyError: "['month'] not found in axis"
In [208]:
us_cci_year=us_cci_year[['year', 'cci']]

US Yearly CCI¶

In [209]:
us_cci_year.head()
Out[209]:
year cci
0 1960 101.013275
1 1961 101.056775
2 1962 101.114400
3 1963 101.116525
4 1964 101.656658
In [27]:
us_cci_og=us_output_gap.merge(us_cci_year,on='year',how='inner')

Correlation between Output Gap and CCI¶

In [28]:
us_cci_og.head()
Out[28]:
year output_gap cci
0 1985 1.124236 100.850008
1 1986 1.376948 101.051883
2 1987 1.695902 100.564608
3 1988 2.743002 100.930058
4 1989 3.289457 100.791175
In [29]:
us_cci_og.output_gap.corr(us_cci_og.cci)
Out[29]:
0.4609753768066784
In [30]:
plt.close()
sns.lineplot(y=us_cci_og['output_gap'],x=us_cci_og['year'],color='black')
sns.lineplot(y=us_cci_og['cci'],x=us_cci_og['year'],ax=plt.twinx(),color='red')
plt.show()
In [226]:
oecd_inflation=pd.read_csv('PRICES_CPI_08062023033246584.csv',parse_dates=['TIME'])
oecd_inflation.head()
Out[226]:
LOCATION Country SUBJECT Subject MEASURE Measure FREQUENCY Frequency TIME Time Unit Code Unit PowerCode Code PowerCode Reference Period Code Reference Period Value Flag Codes Flags
0 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... M Monthly 1967-01-01 Jan-1967 PC Percentage 0 Units NaN NaN 5.253623 NaN NaN
1 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... M Monthly 1967-02-01 Feb-1967 PC Percentage 0 Units NaN NaN 4.946043 NaN NaN
2 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... M Monthly 1967-03-01 Mar-1967 PC Percentage 0 Units NaN NaN 4.557641 NaN NaN
3 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... M Monthly 1967-04-01 Apr-1967 PC Percentage 0 Units NaN NaN 4.347826 NaN NaN
4 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... M Monthly 1967-05-01 May-1967 PC Percentage 0 Units NaN NaN 4.517272 NaN NaN
In [227]:
oecd_inflation.drop(columns=['LOCATION','SUBJECT','MEASURE','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
In [243]:
oecd_hicp=pd.read_csv('PRICES_CPI_08062023034443448.csv',parse_dates=['TIME'])
oecd_hicp.drop(columns=['LOCATION','SUBJECT','MEASURE','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
oecd_hicp.head()
Out[243]:
Country Subject Measure TIME Value
0 Sweden HICP: All items Percentage change on the same period of the pr... 1997-01-01 1.4
1 Sweden HICP: All items Percentage change on the same period of the pr... 1997-02-01 1.1
2 Sweden HICP: All items Percentage change on the same period of the pr... 1997-03-01 1.0
3 Sweden HICP: All items Percentage change on the same period of the pr... 1997-04-01 1.2
4 Sweden HICP: All items Percentage change on the same period of the pr... 1997-05-01 1.2
In [229]:
us_inflation=oecd_inflation[oecd_inflation['Country']=='United States']
us_inflation.head()
Out[229]:
Country Subject Measure TIME Value
13581 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-01-01 0.374532
13582 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-02-01 0.374532
13583 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-03-01 0.374532
13584 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-04-01 0.749064
13585 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-05-01 1.123595

US Monthly Inflation¶

In [230]:
us_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation.reset_index(drop=True,inplace=True)
us_inflation.columns=['month','inflation']
us_inflation.head()
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1469248807.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
Out[230]:
month inflation
0 1956-01-01 0.374532
1 1956-02-01 0.374532
2 1956-03-01 0.374532
3 1956-04-01 0.749064
4 1956-05-01 1.123595

Correlation between Monthly Inflation and CCI¶

In [231]:
us_cci_inflation=us_inflation.merge(us_cci,on='month',how='right')
us_cci_inflation.head()
Out[231]:
month inflation cci
0 1960-01-01 1.034483 101.6451
1 1960-02-01 1.730104 101.3811
2 1960-03-01 1.730104 101.1530
3 1960-04-01 1.724138 101.0272
4 1960-05-01 1.724138 101.0589
In [232]:
us_cci_inflation.inflation.corr(us_cci_inflation.cci)
Out[232]:
-0.564640654505981
In [233]:
plt.close()
sns.lineplot(y=us_cci_inflation['inflation'],x=us_cci_inflation['month'],color='black')
sns.lineplot(y=us_cci_inflation['cci'],x=us_cci_inflation['month'],ax=plt.twinx(),color='red')
plt.show()
In [39]:
oecd_inflation_year=pd.read_csv('PRICES_CPI_31052023125039731.csv')
oecd_inflation_year.head()
Out[39]:
LOCATION Country SUBJECT Subject MEASURE Measure FREQUENCY Frequency TIME Time Unit Code Unit PowerCode Code PowerCode Reference Period Code Reference Period Value Flag Codes Flags
0 GBR United Kingdom CPALTT01 CPI: 01-12 - All items GP Percentage change from previous period A Annual 1956 1956 PC Percentage 0 Units NaN NaN 4.980454 NaN NaN
1 GBR United Kingdom CPALTT01 CPI: 01-12 - All items GP Percentage change from previous period A Annual 1957 1957 PC Percentage 0 Units NaN NaN 3.691303 NaN NaN
2 GBR United Kingdom CPALTT01 CPI: 01-12 - All items GP Percentage change from previous period A Annual 1958 1958 PC Percentage 0 Units NaN NaN 2.992833 NaN NaN
3 GBR United Kingdom CPALTT01 CPI: 01-12 - All items GP Percentage change from previous period A Annual 1959 1959 PC Percentage 0 Units NaN NaN 0.581173 NaN NaN
4 GBR United Kingdom CPALTT01 CPI: 01-12 - All items GP Percentage change from previous period A Annual 1960 1960 PC Percentage 0 Units NaN NaN 1.003573 NaN NaN
In [40]:
oecd_inflation_year.drop(columns=['LOCATION','SUBJECT','MEASURE','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
In [42]:
oecd_hicp_year=pd.read_csv('PRICES_CPI_31052023125328795.csv')
oecd_hicp_year.drop(columns=['LOCATION','SUBJECT','MEASURE','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
oecd_hicp_year.head()
Out[42]:
Country Subject Measure TIME Value
0 Iceland HICP: All items Percentage change from previous period 1996 2.2
1 Iceland HICP: All items Percentage change from previous period 1997 1.8
2 Iceland HICP: All items Percentage change from previous period 1998 1.3
3 Iceland HICP: All items Percentage change from previous period 1999 2.1
4 Iceland HICP: All items Percentage change from previous period 2000 4.4
In [43]:
us_inflation_year=oecd_inflation_year[oecd_inflation_year['Country']=='United States']
us_inflation_year.head()
Out[43]:
Country Subject Measure TIME Value
1960 United States CPI: 01-12 - All items Percentage change from previous period 1956 1.525054
1961 United States CPI: 01-12 - All items Percentage change from previous period 1957 3.341508
1962 United States CPI: 01-12 - All items Percentage change from previous period 1958 2.729161
1963 United States CPI: 01-12 - All items Percentage change from previous period 1959 1.010684
1964 United States CPI: 01-12 - All items Percentage change from previous period 1960 1.457976

US Annual Inflation¶

In [44]:
us_inflation_year.head(10)
Out[44]:
Country Subject Measure TIME Value
1960 United States CPI: 01-12 - All items Percentage change from previous period 1956 1.525054
1961 United States CPI: 01-12 - All items Percentage change from previous period 1957 3.341508
1962 United States CPI: 01-12 - All items Percentage change from previous period 1958 2.729161
1963 United States CPI: 01-12 - All items Percentage change from previous period 1959 1.010684
1964 United States CPI: 01-12 - All items Percentage change from previous period 1960 1.457976
1965 United States CPI: 01-12 - All items Percentage change from previous period 1961 1.070724
1966 United States CPI: 01-12 - All items Percentage change from previous period 1962 1.198773
1967 United States CPI: 01-12 - All items Percentage change from previous period 1963 1.239669
1968 United States CPI: 01-12 - All items Percentage change from previous period 1964 1.278912
1969 United States CPI: 01-12 - All items Percentage change from previous period 1965 1.585169
In [45]:
us_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation_year.reset_index(drop=True,inplace=True)
us_inflation_year.columns=['year','inflation']
us_inflation_year.head()
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/616361686.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
Out[45]:
year inflation
0 1956 1.525054
1 1957 3.341508
2 1958 2.729161
3 1959 1.010684
4 1960 1.457976

Correlation between Annual Inflation and CCI¶

In [46]:
us_cci_inflation_year=us_inflation_year.merge(us_cci_year,on='year',how='right')
us_cci_inflation_year.head()
Out[46]:
year inflation cci
0 1960 1.457976 101.013275
1 1961 1.070724 101.056775
2 1962 1.198773 101.114400
3 1963 1.239669 101.116525
4 1964 1.278912 101.656658
In [47]:
plt.close()
sns.lineplot(y=us_cci_inflation_year['inflation'],x=us_cci_inflation_year['year'],color='black')
sns.lineplot(y=us_cci_inflation_year['cci'],x=us_cci_inflation_year['year'],ax=plt.twinx(),color='red')
plt.show()
In [48]:
us_cci_inflation_year.inflation.corr(us_cci_inflation_year.cci)
Out[48]:
-0.5824738078085799
In [204]:
def summary_stat(var):
    try:
        print('Period:',var.iloc[0,0].year,':',var.iloc[-1,0].year)
    except:
        print('Period:',var.iloc[0,0],':',var.iloc[-1,0])
    print('Observations:',var.iloc[:,1].count())
    print('Mean:',var.iloc[:,1].mean())
    print('Median:',var.iloc[:,1].median())
    print('Max:',var.iloc[:,1].max())
    print('Min:',var.iloc[:,1].min())
    print('Standard Deviation:',var.iloc[:,1].std())
    print('Skewness:',var.iloc[:,1].skew())
    print('Kurtosis:',var.iloc[:,1].kurtosis())
    print(stats.jarque_bera(var.iloc[:,1]))

Data Distributions¶

Output Gap¶

In [170]:
plt.close()
sns.histplot(x=us_output_gap['output_gap'],bins=20)
plt.show()
In [197]:
summary_stat(us_output_gap)
Period: 1985 : 2024
Observations: 40
Mean: -0.5848054885309623
Median: -0.528322093576167
Max: 3.28945657931188
Min: -4.88412437161886
Standard Deviation: 1.8851962204821073
Skewness: -0.26280969536377996
Kurtosis: -0.20600141007151374
Jarque_beraResult(statistic=0.6049571233392901, pvalue=0.7389843306793344)

Monthly CCI¶

In [50]:
plt.close()
sns.histplot(x=us_cci['cci'],bins=20)
plt.show()
In [200]:
summary_stat(us_cci)
Period: 1960 : 2023
Observations: 760
Mean: 99.99999948684196
Median: 100.49019999999999
Max: 102.89
Min: 96.08473
Standard Deviation: 1.4871340810746276
Skewness: -0.5386067647822662
Kurtosis: -0.5015786220939882
Jarque_beraResult(statistic=44.713896191629075, pvalue=1.9520940419681665e-10)

Annual CCI¶

In [51]:
plt.close()
sns.histplot(x=us_cci_year['cci'],bins=20)
plt.show()

Monthly Inflation¶

In [52]:
plt.close()
sns.histplot(x=us_inflation['inflation'],bins=20)
plt.show()

Annual Inflation¶

In [53]:
plt.close()
sns.histplot(x=us_inflation_year['inflation'],bins=20)
plt.show()
In [54]:
us_exp_infl=pd.read_excel('US_EXP_INFL.xls',parse_dates=['Date'])
us_exp_infl.head()
Out[54]:
Date G_BP_To_12M
0 1946-06-01 NaN
1 1946-12-01 -5.64
2 1947-06-01 -7.16
3 1947-12-01 -0.56
4 1948-06-01 -1.52
In [55]:
us_exp_infl=us_exp_infl[us_exp_infl['Date'].dt.month==12]
In [56]:
us_exp_infl['year']=us_exp_infl['Date'].dt.year
In [57]:
us_exp_infl.head()
Out[57]:
Date G_BP_To_12M year
1 1946-12-01 -5.64 1946
3 1947-12-01 -0.56 1947
5 1948-12-01 -2.69 1948
7 1949-12-01 -2.18 1949
9 1950-12-01 4.05 1950
In [58]:
us_exp_infl.drop(columns='Date',inplace=True)
In [59]:
us_exp_infl.columns=['exp_inflation','year']

US Annual Expected Inflation¶

In [60]:
us_exp_infl.head()
Out[60]:
exp_inflation year
1 -5.64 1946
3 -0.56 1947
5 -2.69 1948
7 -2.18 1949
9 4.05 1950
In [61]:
us_cci_exp_inflation=us_exp_infl.merge(us_cci_year,on='year',how='right')
us_cci_exp_inflation.head()
Out[61]:
exp_inflation year cci
0 0.65 1960 101.013275
1 1.21 1961 101.056775
2 1.10 1962 101.114400
3 1.00 1963 101.116525
4 1.25 1964 101.656658

Correlation between Annual Expected Inflation and CCI¶

In [62]:
plt.close()
sns.lineplot(y=us_cci_exp_inflation['exp_inflation'],x=us_cci_exp_inflation['year'],color='black')
sns.lineplot(y=us_cci_exp_inflation['cci'],x=us_cci_exp_inflation['year'],ax=plt.twinx(),color='red')
plt.show()
In [63]:
us_cci_exp_inflation.exp_inflation.corr(us_cci_exp_inflation.cci)
Out[63]:
-0.44566605057560227
In [64]:
oecd_interest_rate=pd.read_csv('MEI_FIN_31052023124246883.csv')
oecd_interest_rate.head()
Out[64]:
SUBJECT Subject LOCATION Country FREQUENCY Frequency TIME Time Unit Code Unit PowerCode Code PowerCode Reference Period Code Reference Period Value Flag Codes Flags
0 IR3TIB Short-term interest rates, Per cent per annum AUS Australia A Annual 1968 1968 PC Percentage 0 Units NaN NaN 5.116667 NaN NaN
1 IR3TIB Short-term interest rates, Per cent per annum AUS Australia A Annual 1969 1969 PC Percentage 0 Units NaN NaN 5.566667 NaN NaN
2 IR3TIB Short-term interest rates, Per cent per annum AUS Australia A Annual 1970 1970 PC Percentage 0 Units NaN NaN 7.108333 NaN NaN
3 IR3TIB Short-term interest rates, Per cent per annum AUS Australia A Annual 1971 1971 PC Percentage 0 Units NaN NaN 7.008333 NaN NaN
4 IR3TIB Short-term interest rates, Per cent per annum AUS Australia A Annual 1972 1972 PC Percentage 0 Units NaN NaN 5.083333 NaN NaN
In [65]:
oecd_interest_rate.drop(columns=['SUBJECT','LOCATION','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
oecd_interest_rate.head()
Out[65]:
Subject Country TIME Value
0 Short-term interest rates, Per cent per annum Australia 1968 5.116667
1 Short-term interest rates, Per cent per annum Australia 1969 5.566667
2 Short-term interest rates, Per cent per annum Australia 1970 7.108333
3 Short-term interest rates, Per cent per annum Australia 1971 7.008333
4 Short-term interest rates, Per cent per annum Australia 1972 5.083333
In [66]:
us_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='United States']
us_interest_rate.head()
Out[66]:
Subject Country TIME Value
1084 Short-term interest rates, Per cent per annum United States 1965 4.344167
1085 Short-term interest rates, Per cent per annum United States 1966 5.483333
1086 Short-term interest rates, Per cent per annum United States 1967 5.020833
1087 Short-term interest rates, Per cent per annum United States 1968 5.859167
1088 Short-term interest rates, Per cent per annum United States 1969 7.760833

US Short-term Interest Rate¶

In [67]:
us_interest_rate.drop(columns=['Subject','Country'],inplace=True)
us_interest_rate.reset_index(drop=True,inplace=True)
us_interest_rate.columns=['year','interest_rate']
us_interest_rate.head()
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3041759583.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_interest_rate.drop(columns=['Subject','Country'],inplace=True)
Out[67]:
year interest_rate
0 1965 4.344167
1 1966 5.483333
2 1967 5.020833
3 1968 5.859167
4 1969 7.760833
In [68]:
us_taylor_rule=us_interest_rate.merge(us_inflation_year,on='year',how='inner')
us_taylor_rule.head()
Out[68]:
year interest_rate inflation
0 1965 4.344167 1.585169
1 1966 5.483333 3.015075
2 1967 5.020833 2.772786
3 1968 5.859167 4.271796
4 1969 7.760833 5.462386
In [69]:
us_taylor_rule['real_interest_rate']=us_taylor_rule['interest_rate']-us_taylor_rule['inflation']
In [70]:
us_taylor_rule.head()
Out[70]:
year interest_rate inflation real_interest_rate
0 1965 4.344167 1.585169 2.758998
1 1966 5.483333 3.015075 2.468258
2 1967 5.020833 2.772786 2.248047
3 1968 5.859167 4.271796 1.587371
4 1969 7.760833 5.462386 2.298447
In [71]:
us_taylor_rule['infl_dev']=us_inflation_year['inflation']-2
In [72]:
us_taylor_rule.head()
Out[72]:
year interest_rate inflation real_interest_rate infl_dev
0 1965 4.344167 1.585169 2.758998 -0.474946
1 1966 5.483333 3.015075 2.468258 1.341508
2 1967 5.020833 2.772786 2.248047 0.729161
3 1968 5.859167 4.271796 1.587371 -0.989316
4 1969 7.760833 5.462386 2.298447 -0.542024

US Dataset for Taylor Rule¶

In [73]:
us_taylor_rule=us_taylor_rule.merge(us_output_gap,on='year',how='inner')
us_taylor_rule.head()
Out[73]:
year interest_rate inflation real_interest_rate infl_dev output_gap
0 1985 8.047500 3.545644 4.501856 3.744812 1.124236
1 1986 6.518333 1.898048 4.620285 4.501684 1.376948
2 1987 6.860833 3.664563 3.196270 5.630964 1.695902
3 1988 7.727500 4.077741 3.649759 9.254470 2.743002
4 1989 9.085000 4.827003 4.257997 11.549200 3.289457

Check of possible correlations with interest rate¶

In [74]:
us_taylor_rule_cci=us_taylor_rule.merge(us_cci_year,on='year',how='inner')
In [75]:
us_taylor_rule_cci[us_taylor_rule_cci['year']<2023]
Out[75]:
year interest_rate inflation real_interest_rate infl_dev output_gap cci
0 1985 8.047500 3.545644 4.501856 3.744812 1.124236 100.850008
1 1986 6.518333 1.898048 4.620285 4.501684 1.376948 101.051883
2 1987 6.860833 3.664563 3.196270 5.630964 1.695902 100.564608
3 1988 7.727500 4.077741 3.649759 9.254470 2.743002 100.930058
4 1989 9.085000 4.827003 4.257997 11.549200 3.289457 100.791175
5 1990 8.147500 5.397956 2.749544 8.334710 2.053658 99.454773
6 1991 5.835000 4.234964 1.600036 4.131427 -1.015399 98.972317
7 1992 3.681667 3.028820 0.652847 1.212435 -0.431392 98.924284
8 1993 3.174167 2.951657 0.222510 2.300536 -0.695441 99.632367
9 1994 4.629167 2.607442 2.021725 1.545644 0.119769 100.740667
10 1995 5.916667 2.805420 3.111247 -0.101952 -0.584526 100.729008
11 1996 5.390000 2.931204 2.458796 1.664563 -0.472119 100.912258
12 1997 5.615833 2.337690 3.278143 2.077741 0.062840 102.086683
13 1998 5.466667 1.552279 3.914388 2.827003 0.490545 102.234242
14 1999 5.330000 2.188027 3.141973 3.397956 1.201590 102.393742
15 2000 6.455833 3.376857 3.078976 2.234964 1.334529 102.562908
16 2001 3.686667 2.826171 0.860496 1.028820 -1.186268 100.404999
17 2002 1.725833 1.586032 0.139801 0.951657 -2.354312 100.396385
18 2003 1.150833 2.270095 -1.119262 0.607442 -2.070849 100.235702
19 2004 1.563333 2.677237 -1.113904 0.805420 -0.595187 101.069433
20 2005 3.511667 3.392747 0.118920 0.931204 0.633614 100.299339
21 2006 5.153333 3.225944 1.927389 0.337690 1.229935 100.164591
22 2007 5.268333 2.852673 2.415660 -0.447721 1.129645 99.946445
23 2008 2.965000 3.839100 -0.874100 0.188027 -0.737116 97.290395
24 2009 0.555833 -0.355546 0.911380 1.376857 -4.884124 97.612842
25 2010 0.311667 1.640043 -1.328376 0.826171 -3.728458 98.276032
26 2011 0.303333 3.156842 -2.853509 -0.413968 -3.684574 97.753128
27 2012 0.282500 2.069337 -1.786837 0.270095 -3.041275 98.837075
28 2013 0.166667 1.464833 -1.298166 0.677237 -2.871107 99.171598
29 2014 0.124167 1.622223 -1.498056 1.392747 -2.377112 99.773988
30 2015 0.226667 0.118627 0.108040 1.225944 -1.572297 100.814817
31 2016 0.644167 1.261583 -0.617416 0.852673 -1.774994 100.696808
32 2017 1.152500 2.130110 -0.977610 1.839100 -1.419398 101.292675
33 2018 2.188333 2.442583 -0.254250 -2.355546 -0.375937 101.461050
34 2019 2.207500 1.812210 0.395290 -0.359957 0.116767 101.237067
35 2020 0.533636 1.233584 -0.699948 1.156842 -4.162269 99.426038
36 2021 0.114167 4.697859 -4.583692 0.069337 0.045048 98.985485
37 2022 2.227500 8.002800 -5.775300 -0.535167 0.306406 96.753597
In [76]:
us_taylor_rule_cci=us_taylor_rule_cci[us_taylor_rule_cci['year']<2023]
In [77]:
us_taylor_rule.to_csv('us_taylor.csv',index=False)
In [78]:
plt.close()
sns.lineplot(y=us_taylor_rule_cci['interest_rate'],x=us_taylor_rule_cci['year'])
sns.lineplot(y=us_taylor_rule_cci['output_gap'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='green')
sns.lineplot(y=us_taylor_rule_cci['cci'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='orange')
plt.show()
In [79]:
plt.close()
sns.lineplot(y=us_taylor_rule_cci['interest_rate'],x=us_taylor_rule_cci['year'])
sns.lineplot(y=us_taylor_rule_cci['cci'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='orange')
plt.show()
In [80]:
plt.close()
sns.lineplot(y=us_taylor_rule_cci['interest_rate'],x=us_taylor_rule_cci['year'])
sns.lineplot(y=us_taylor_rule_cci['output_gap'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='green')
plt.show()

sns.lineplot(y=us_taylor_rule_cci['cci'],x=us_taylor_rule_cci['year'],color='orange')
plt.show()
In [81]:
us_interest_rate_effect=us_output_gap.merge(us_cci_year.merge(us_interest_rate,on='year',how='inner'),on='year',how='inner')
us_interest_rate_effect.drop(columns='cci_growth_rate',inplace=True)
us_interest_rate_effect.head()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2526521720.py in <module>
      1 us_interest_rate_effect=us_output_gap.merge(us_cci_year.merge(us_interest_rate,on='year',how='inner'),on='year',how='inner')
----> 2 us_interest_rate_effect.drop(columns='cci_growth_rate',inplace=True)
      3 us_interest_rate_effect.head()

~/opt/anaconda3/lib/python3.9/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    309                     stacklevel=stacklevel,
    310                 )
--> 311             return func(*args, **kwargs)
    312 
    313         return wrapper

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   4955                 weight  1.0     0.8
   4956         """
-> 4957         return super().drop(
   4958             labels=labels,
   4959             axis=axis,

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors)
   4265         for axis, labels in axes.items():
   4266             if labels is not None:
-> 4267                 obj = obj._drop_axis(labels, axis, level=level, errors=errors)
   4268 
   4269         if inplace:

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors, consolidate, only_slice)
   4309                 new_axis = axis.drop(labels, level=level, errors=errors)
   4310             else:
-> 4311                 new_axis = axis.drop(labels, errors=errors)
   4312             indexer = axis.get_indexer(new_axis)
   4313 

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/base.py in drop(self, labels, errors)
   6659         if mask.any():
   6660             if errors != "ignore":
-> 6661                 raise KeyError(f"{list(labels[mask])} not found in axis")
   6662             indexer = indexer[~mask]
   6663         return self.delete(indexer)

KeyError: "['cci_growth_rate'] not found in axis"
In [82]:
us_interest_rate_effect['interaction']=us_interest_rate_effect['cci']*us_interest_rate_effect['interest_rate']
In [ ]:
us_interest_rate_effect.head()
In [ ]:
us_interest_rate_effect.to_csv('us_interest_rate_effect.csv',index=False)
In [83]:
us_taylor_rule_pre_gr=us_taylor_rule[us_taylor_rule['year']<2008]
us_taylor_rule_pre_gr.to_csv('taylor_pre_gr.csv',index=False)
In [84]:
us_taylor_rule_post_gr=us_taylor_rule[(us_taylor_rule['year']<2020)&(us_taylor_rule['year']>2007)]
us_taylor_rule_post_gr.to_csv('taylor_post_gr.csv',index=False)

Quarters Data¶

Output Gap¶

In [85]:
us_output_gap['year']=pd.to_datetime(us_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3039412941.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_output_gap['year']=pd.to_datetime(us_output_gap['year'],format='%Y')
In [86]:
us_output_gap.head()
Out[86]:
year output_gap
0 1985-01-01 1.124236
1 1986-01-01 1.376948
2 1987-01-01 1.695902
3 1988-01-01 2.743002
4 1989-01-01 3.289457
In [87]:
us_og_quarters=us_output_gap.resample('Q',on='year').mean().reset_index()
us_og_quarters['year']=us_og_quarters['year'].dt.to_period('Q')
us_og_quarters.columns=['quarter','output_gap']
us_og_quarters.head()
Out[87]:
quarter output_gap
0 1985Q1 1.124236
1 1985Q2 NaN
2 1985Q3 NaN
3 1985Q4 NaN
4 1986Q1 1.376948
In [88]:
us_og_quarters['output_gap']=us_og_quarters['output_gap'].ffill()
us_og_quarters.head()
Out[88]:
quarter output_gap
0 1985Q1 1.124236
1 1985Q2 1.124236
2 1985Q3 1.124236
3 1985Q4 1.124236
4 1986Q1 1.376948
In [89]:
us_og_quarters.quarter=us_og_quarters.quarter.astype(str)

CCI¶

In [90]:
us_cci_quarters=us_cci.resample('Q',on='month').mean().reset_index()
us_cci_quarters['month']=us_cci_quarters['month'].dt.to_period('Q')
us_cci_quarters.columns=['quarter','cci']
us_cci_quarters.head()
Out[90]:
quarter cci
0 1960Q1 101.393067
1 1960Q2 101.078300
2 1960Q3 100.997833
3 1960Q4 100.583900
4 1961Q1 100.686933
In [91]:
us_cci_quarters.quarter=us_cci_quarters.quarter.astype(str)
In [92]:
plt.close()
sns.histplot(x=us_cci_quarters['cci'],bins=20)
plt.show()

Inflation¶

In [234]:
oecd_inflation_quarters=pd.read_csv('PRICES_CPI_08062023033824651.csv')
oecd_inflation_quarters.head()
Out[234]:
LOCATION Country SUBJECT Subject MEASURE Measure FREQUENCY Frequency TIME Time Unit Code Unit PowerCode Code PowerCode Reference Period Code Reference Period Value Flag Codes Flags
0 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... Q Quarterly 1967-Q1 Q1-1967 PC Percentage 0 Units NaN NaN 4.917541 NaN NaN
1 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... Q Quarterly 1967-Q2 Q2-1967 PC Percentage 0 Units NaN NaN 4.634002 NaN NaN
2 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... Q Quarterly 1967-Q3 Q3-1967 PC Percentage 0 Units NaN NaN 10.617140 NaN NaN
3 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... Q Quarterly 1967-Q4 Q4-1967 PC Percentage 0 Units NaN NaN 10.479210 NaN NaN
4 DNK Denmark CPALTT01 CPI: 01-12 - All items GY Percentage change on the same period of the pr... Q Quarterly 1968-Q1 Q1-1968 PC Percentage 0 Units NaN NaN 10.374390 NaN NaN
In [235]:
oecd_inflation_quarters.drop(columns=['LOCATION','SUBJECT','MEASURE','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
In [236]:
us_inflation_quarters=oecd_inflation_quarters[oecd_inflation_quarters['Country']=='United States']
us_inflation_quarters.head()
Out[236]:
Country Subject Measure TIME Value
3947 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-Q1 0.374532
3948 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-Q2 1.248439
3949 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-Q3 1.987578
3950 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1956-Q4 2.481390
3951 United States CPI: 01-12 - All items Percentage change on the same period of the pr... 1957-Q1 3.358209
In [237]:
us_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation_quarters.reset_index(drop=True,inplace=True)
us_inflation_quarters.columns=['quarter','inflation']
us_inflation_quarters.head()
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3070307878.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
Out[237]:
quarter inflation
0 1956-Q1 0.374532
1 1956-Q2 1.248439
2 1956-Q3 1.987578
3 1956-Q4 2.481390
4 1957-Q1 3.358209
In [238]:
us_inflation_quarters=us_inflation_quarters.replace('-', '',regex=True)
us_inflation_quarters.head()
Out[238]:
quarter inflation
0 1956Q1 0.374532
1 1956Q2 1.248439
2 1956Q3 1.987578
3 1956Q4 2.481390
4 1957Q1 3.358209
In [239]:
plt.close()
sns.histplot(x=us_inflation_quarters['inflation'],bins=20)
plt.show()

Correlation between quarter inflation and CCI¶

In [335]:
us_cci_inflation_quarters=us_inflation_quarters.merge(us_cci_quarters,on='quarter',how='inner')
us_cci_inflation_quarters.quarter=pd.to_datetime(us_cci_inflation_quarters.quarter).dt.to_period('Q')
us_cci_inflation_quarters.quarter=us_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)
us_cci_inflation_quarters.head(10)
Out[335]:
quarter inflation cci
0 1960.1 1.497696 101.393067
1 1960.2 1.722158 101.078300
2 1960.3 1.254276 100.997833
3 1960.4 1.360544 100.583900
4 1961.1 1.475596 100.686933
5 1961.2 0.902935 101.081100
6 1961.3 1.238739 101.270833
7 1961.4 0.671141 101.188233
8 1962.1 0.894855 101.433900
9 1962.2 1.342282 100.975533
In [375]:
sns.lineplot(y=us_cci_inflation_quarters['inflation'],x=us_cci_inflation_quarters['quarter'],color='black',label='inflation').legend()
sns.lineplot(y=us_cci_inflation_quarters['cci'],x=us_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend(loc='upper left')
plt.show()
In [242]:
us_cci_inflation_quarters.inflation.corr(us_cci_inflation_quarters.cci)
Out[242]:
-0.5697632305181483

US Expected Inflation¶

In [102]:
us_exp_infl_quarters=pd.read_excel('US_EXP_INFL.xls',parse_dates=['Date'])
us_exp_infl_quarters.columns=['date','exp_inflation']
us_exp_infl_quarters.head()
Out[102]:
date exp_inflation
0 1946-06-01 NaN
1 1946-12-01 -5.64
2 1947-06-01 -7.16
3 1947-12-01 -0.56
4 1948-06-01 -1.52
In [103]:
us_exp_infl_quarters=us_exp_infl_quarters.resample('Q',on='date').mean().reset_index()
In [104]:
us_exp_infl_quarters['date']=us_exp_infl_quarters['date'].dt.to_period('Q')
us_exp_infl_quarters.head()
Out[104]:
date exp_inflation
0 1946Q2 NaN
1 1946Q3 NaN
2 1946Q4 -5.64
3 1947Q1 NaN
4 1947Q2 -7.16
In [105]:
us_exp_infl_quarters['exp_inflation']=us_exp_infl_quarters['exp_inflation'].ffill()
us_exp_infl_quarters.head()
Out[105]:
date exp_inflation
0 1946Q2 NaN
1 1946Q3 NaN
2 1946Q4 -5.64
3 1947Q1 -5.64
4 1947Q2 -7.16
In [106]:
us_exp_infl_quarters.columns=['quarter','exp_inflation']
In [107]:
us_exp_infl_quarters.quarter=us_exp_infl_quarters.quarter.astype(str)

Correlation between quarter expected inflation and CCI¶

In [108]:
us_cci_exp_inflation_quarters=us_exp_infl_quarters.merge(us_cci_quarters,on='quarter',how='inner')
us_cci_exp_inflation_quarters.head()
Out[108]:
quarter exp_inflation cci
0 1960Q1 1.05 101.393067
1 1960Q2 0.70 101.078300
2 1960Q3 0.70 100.997833
3 1960Q4 0.65 100.583900
4 1961Q1 0.65 100.686933
In [282]:
plt.close()
sns.lineplot(y=us_cci_exp_inflation_quarters['exp_inflation'],x=us_cci_exp_inflation_quarters['quarter'].to_daytime(),color='black')
sns.lineplot(y=us_cci_exp_inflation_quarters['cci'],x=us_cci_exp_inflation_quarters['quarter'].to_daytime(),ax=plt.twinx(),color='red')
plt.show()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1803951202.py in <module>
      1 plt.close()
----> 2 sns.lineplot(y=us_cci_exp_inflation_quarters['exp_inflation'],x=us_cci_exp_inflation_quarters['quarter'].to_daytime(),color='black')
      3 sns.lineplot(y=us_cci_exp_inflation_quarters['cci'],x=us_cci_exp_inflation_quarters['quarter'].to_daytime(),ax=plt.twinx(),color='red')
      4 plt.show()

~/opt/anaconda3/lib/python3.9/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5573         ):
   5574             return self[name]
-> 5575         return object.__getattribute__(self, name)
   5576 
   5577     def __setattr__(self, name: str, value) -> None:

AttributeError: 'Series' object has no attribute 'to_daytime'
In [110]:
us_cci_exp_inflation.exp_inflation.corr(us_cci_exp_inflation.cci)
Out[110]:
-0.44566605057560227

Short-Term Interest Rate¶

In [111]:
oecd_interest_rate_quarters=pd.read_csv('MEI_FIN_01062023190017139.csv')
oecd_interest_rate_quarters.head()
Out[111]:
SUBJECT Subject LOCATION Country FREQUENCY Frequency TIME Time Unit Code Unit PowerCode Code PowerCode Reference Period Code Reference Period Value Flag Codes Flags
0 IR3TIB Short-term interest rates, Per cent per annum AUS Australia Q Quarterly 1968-Q1 Q1-1968 PC Percentage 0 Units NaN NaN 5.133333 NaN NaN
1 IR3TIB Short-term interest rates, Per cent per annum AUS Australia Q Quarterly 1968-Q2 Q2-1968 PC Percentage 0 Units NaN NaN 5.316667 NaN NaN
2 IR3TIB Short-term interest rates, Per cent per annum AUS Australia Q Quarterly 1968-Q3 Q3-1968 PC Percentage 0 Units NaN NaN 5.083333 NaN NaN
3 IR3TIB Short-term interest rates, Per cent per annum AUS Australia Q Quarterly 1968-Q4 Q4-1968 PC Percentage 0 Units NaN NaN 4.933333 NaN NaN
4 IR3TIB Short-term interest rates, Per cent per annum AUS Australia Q Quarterly 1969-Q1 Q1-1969 PC Percentage 0 Units NaN NaN 5.116667 NaN NaN
In [112]:
oecd_interest_rate_quarters.drop(columns=['SUBJECT','LOCATION','FREQUENCY','Frequency','Time','Unit Code','Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period','Flag Codes','Flags'],inplace=True)
oecd_interest_rate_quarters.head()
Out[112]:
Subject Country TIME Value
0 Short-term interest rates, Per cent per annum Australia 1968-Q1 5.133333
1 Short-term interest rates, Per cent per annum Australia 1968-Q2 5.316667
2 Short-term interest rates, Per cent per annum Australia 1968-Q3 5.083333
3 Short-term interest rates, Per cent per annum Australia 1968-Q4 4.933333
4 Short-term interest rates, Per cent per annum Australia 1969-Q1 5.116667
In [113]:
us_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='United States']
us_interest_rate_quarters.head()
Out[113]:
Subject Country TIME Value
4407 Short-term interest rates, Per cent per annum United States 1964-Q3 3.863333
4408 Short-term interest rates, Per cent per annum United States 1964-Q4 4.023334
4409 Short-term interest rates, Per cent per annum United States 1965-Q1 4.196667
4410 Short-term interest rates, Per cent per annum United States 1965-Q2 4.303333
4411 Short-term interest rates, Per cent per annum United States 1965-Q3 4.310000
In [114]:
us_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
us_interest_rate_quarters.reset_index(drop=True,inplace=True)
us_interest_rate_quarters.columns=['quarter','interest_rate']
us_interest_rate_quarters.head()
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3081482467.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Out[114]:
quarter interest_rate
0 1964-Q3 3.863333
1 1964-Q4 4.023334
2 1965-Q1 4.196667
3 1965-Q2 4.303333
4 1965-Q3 4.310000
In [115]:
us_interest_rate_quarters=us_interest_rate_quarters.replace('-', '',regex=True)
us_interest_rate_quarters.quarter=us_interest_rate_quarters.quarter.astype(str)
us_interest_rate_quarters.head()
Out[115]:
quarter interest_rate
0 1964Q3 3.863333
1 1964Q4 4.023334
2 1965Q1 4.196667
3 1965Q2 4.303333
4 1965Q3 4.310000
In [116]:
us_interest_rate_quarters['prev_int_rate']=us_interest_rate_quarters['interest_rate'].shift(1)

Taylor Rule¶

In [117]:
us_taylor_rule_quarters=us_interest_rate_quarters.merge(us_inflation_quarters,on='quarter',how='inner')
us_taylor_rule_quarters.head()
Out[117]:
quarter interest_rate prev_int_rate inflation
0 1964Q3 3.863333 NaN 0.431034
1 1964Q4 4.023334 3.863333 0.321888
2 1965Q1 4.196667 4.023334 0.213904
3 1965Q2 4.303333 4.196667 0.747065
4 1965Q3 4.310000 4.303333 0.423729
In [118]:
us_taylor_rule_quarters['real_interest_rate']=us_taylor_rule_quarters['interest_rate']-us_taylor_rule_quarters['inflation']
us_taylor_rule_quarters['infl_dev']=us_taylor_rule_quarters['inflation']-2
us_taylor_rule_quarters=us_taylor_rule_quarters.merge(us_og_quarters,on='quarter',how='inner')
us_taylor_rule_quarters.head()
Out[118]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
0 1985Q1 8.616667 9.386666 0.633112 7.983555 -1.366888 1.124236
1 1985Q2 7.950000 8.616667 1.226801 6.723199 -0.773199 1.124236
2 1985Q3 7.793334 7.950000 0.714730 7.078604 -1.285270 1.124236
3 1985Q4 7.830000 7.793334 0.894786 6.935214 -1.105214 1.124236
4 1986Q1 7.583333 7.830000 0.214067 7.369266 -1.785933 1.376948
In [119]:
us_taylor_rule_quarters.head(95)
Out[119]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
0 1985Q1 8.616667 9.386666 0.633112 7.983555 -1.366888 1.124236
1 1985Q2 7.950000 8.616667 1.226801 6.723199 -0.773199 1.124236
2 1985Q3 7.793334 7.950000 0.714730 7.078604 -1.285270 1.124236
3 1985Q4 7.830000 7.793334 0.894786 6.935214 -1.105214 1.124236
4 1986Q1 7.583333 7.830000 0.214067 7.369266 -1.785933 1.376948
... ... ... ... ... ... ... ...
90 2007Q3 5.423333 5.316667 0.275929 5.147404 -1.724071 1.129645
91 2007Q4 5.023334 5.423333 0.711214 4.312120 -1.288785 1.129645
92 2008Q1 3.230000 5.023334 1.136774 2.093226 -0.863226 -0.737116
93 2008Q2 2.756667 3.230000 2.195345 0.561322 0.195345 -0.737116
94 2008Q3 3.056667 2.756667 1.163055 1.893612 -0.836945 -0.737116

95 rows × 7 columns

In [120]:
us_taylor_rule_quarters.to_csv('taylor_quarters.csv',index=False)
In [121]:
us_taylor_rule_quarters.loc[0:91]
Out[121]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
0 1985Q1 8.616667 9.386666 0.633112 7.983555 -1.366888 1.124236
1 1985Q2 7.950000 8.616667 1.226801 6.723199 -0.773199 1.124236
2 1985Q3 7.793334 7.950000 0.714730 7.078604 -1.285270 1.124236
3 1985Q4 7.830000 7.793334 0.894786 6.935214 -1.105214 1.124236
4 1986Q1 7.583333 7.830000 0.214067 7.369266 -1.785933 1.376948
... ... ... ... ... ... ... ...
87 2006Q4 5.323333 5.393333 -0.852040 6.175373 -2.852040 1.229935
88 2007Q1 5.310000 5.323333 1.019170 4.290830 -0.980830 1.129645
89 2007Q2 5.316667 5.310000 1.917329 3.399338 -0.082671 1.129645
90 2007Q3 5.423333 5.316667 0.275929 5.147404 -1.724071 1.129645
91 2007Q4 5.023334 5.423333 0.711214 4.312120 -1.288785 1.129645

92 rows × 7 columns

In [122]:
us_taylor_rule_quarters.loc[91:140]
Out[122]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
91 2007Q4 5.023334 5.423333 0.711214 4.312120 -1.288785 1.129645
92 2008Q1 3.230000 5.023334 1.136774 2.093226 -0.863226 -0.737116
93 2008Q2 2.756667 3.230000 2.195345 0.561322 0.195345 -0.737116
94 2008Q3 3.056667 2.756667 1.163055 1.893612 -0.836945 -0.737116
95 2008Q4 2.816667 3.056667 -2.828529 5.645196 -4.828529 -0.737116
96 2009Q1 1.083333 2.816667 -0.497633 1.580966 -2.497633 -4.884124
97 2009Q2 0.616667 1.083333 1.060302 -0.443635 -0.939698 -4.884124
98 2009Q3 0.300000 0.616667 0.679072 -0.379072 -1.320928 -4.884124
99 2009Q4 0.223333 0.300000 0.201189 0.022145 -1.798811 -4.884124
100 2010Q1 0.206667 0.223333 0.401415 -0.194748 -1.598585 -3.728458
101 2010Q2 0.423333 0.206667 0.475072 -0.051739 -1.524928 -3.728458
102 2010Q3 0.336667 0.423333 0.093251 0.243416 -1.906750 -3.728458
103 2010Q4 0.280000 0.336667 0.294916 -0.014916 -1.705084 -3.728458
104 2011Q1 0.283333 0.280000 1.264822 -0.981489 -0.735178 -3.684574
105 2011Q2 0.220000 0.283333 1.743311 -1.523311 -0.256689 -3.684574
106 2011Q3 0.286667 0.220000 0.408518 -0.121851 -1.591482 -3.684574
107 2011Q4 0.423333 0.286667 -0.152056 0.575389 -2.152056 -3.684574
108 2012Q1 0.330000 0.423333 0.795639 -0.465639 -1.204361 -3.041275
109 2012Q2 0.300000 0.330000 0.827532 -0.527532 -1.172468 -3.041275
110 2012Q3 0.266667 0.300000 0.219328 0.047338 -1.780672 -3.041275
111 2012Q4 0.233333 0.266667 0.036040 0.197293 -1.963960 -3.041275
112 2013Q1 0.220000 0.233333 0.590330 -0.370330 -1.409670 -2.871107
113 2013Q2 0.196667 0.220000 0.540981 -0.344314 -1.459019 -2.871107
114 2013Q3 0.123333 0.196667 0.377979 -0.254646 -1.622021 -2.871107
115 2013Q4 0.126667 0.123333 -0.279068 0.405734 -2.279068 -2.871107
116 2014Q1 0.123333 0.126667 0.761223 -0.637889 -1.238777 -2.377112
117 2014Q2 0.113333 0.123333 1.180868 -1.067535 -0.819132 -2.377112
118 2014Q3 0.126667 0.113333 0.114676 0.011991 -1.885324 -2.377112
119 2014Q4 0.133333 0.126667 -0.803352 0.936685 -2.803352 -2.377112
120 2015Q1 0.150000 0.133333 -0.543199 0.693199 -2.543199 -1.572297
121 2015Q2 0.153333 0.150000 1.205596 -1.052263 -0.794404 -1.572297
122 2015Q3 0.240000 0.153333 0.262677 -0.022677 -1.737323 -1.572297
123 2015Q4 0.363333 0.240000 -0.449844 0.813177 -2.449844 -1.572297
124 2016Q1 0.553333 0.363333 0.064634 0.488699 -1.935366 -1.774994
125 2016Q2 0.556667 0.553333 1.172351 -0.615684 -0.827649 -1.774994
126 2016Q3 0.700000 0.556667 0.332682 0.367318 -1.667318 -1.774994
127 2016Q4 0.766667 0.700000 0.222574 0.544093 -1.777426 -1.774994
128 2017Q1 0.916667 0.766667 0.790737 0.125930 -1.209263 -1.419398
129 2017Q2 1.080000 0.916667 0.543518 0.536482 -1.456482 -1.419398
130 2017Q3 1.240000 1.080000 0.396616 0.843384 -1.603384 -1.419398
131 2017Q4 1.373333 1.240000 0.370630 1.002703 -1.629370 -1.419398
132 2018Q1 1.830000 1.373333 0.886118 0.943882 -1.113882 -0.375937
133 2018Q2 2.183333 1.830000 1.033076 1.150257 -0.966924 -0.375937
134 2018Q3 2.200000 2.183333 0.327268 1.872732 -1.672732 -0.375937
135 2018Q4 2.540000 2.200000 -0.057495 2.597495 -2.057495 -0.375937
136 2019Q1 2.520000 2.540000 0.335116 2.184884 -1.664884 0.116767
137 2019Q2 2.403333 2.520000 1.198513 1.204820 -0.801487 0.116767
138 2019Q3 2.103333 2.403333 0.274166 1.829167 -1.725834 0.116767
139 2019Q4 1.803333 2.103333 0.213018 1.590315 -1.786982 0.116767
140 2020Q1 1.530000 1.803333 0.419427 1.110573 -1.580573 -4.162269
In [123]:
us_taylor_rule_quarters_pre_gr=us_taylor_rule_quarters.loc[0:91]
us_taylor_rule_quarters_pre_gr.to_csv('taylor_pre_gr.csv',index=False)
In [124]:
us_taylor_rule_quarters_post_gr=us_taylor_rule_quarters.loc[91:]
us_taylor_rule_quarters_post_gr.to_csv('taylor_post_gr.csv',index=False)
In [125]:
us_taylor_rule_quarters_post_gr=us_taylor_rule_quarters.loc[91:139]
us_taylor_rule_quarters_post_gr.to_csv('taylor_post_gr.csv',index=False)

Taylor Rule with Inflation Expectations¶

In [126]:
us_taylor_rule_exp_quarters=us_interest_rate_quarters.merge(us_exp_infl_quarters,on='quarter',how='inner')
us_taylor_rule_exp_quarters.head()
Out[126]:
quarter interest_rate prev_int_rate exp_inflation
0 1964Q3 3.863333 NaN 1.24
1 1964Q4 4.023334 3.863333 1.25
2 1965Q1 4.196667 4.023334 1.25
3 1965Q2 4.303333 4.196667 1.07
4 1965Q3 4.310000 4.303333 1.07
In [127]:
us_taylor_rule_exp_quarters['exp_infl_dev']=us_taylor_rule_exp_quarters['exp_inflation']-2
us_taylor_rule_exp_quarters=us_taylor_rule_exp_quarters.merge(us_og_quarters,on='quarter',how='inner')
us_taylor_rule_exp_quarters.head()
Out[127]:
quarter interest_rate prev_int_rate exp_inflation exp_infl_dev output_gap
0 1985Q1 8.616667 9.386666 4.78 2.78 1.124236
1 1985Q2 7.950000 8.616667 4.56 2.56 1.124236
2 1985Q3 7.793334 7.950000 4.56 2.56 1.124236
3 1985Q4 7.830000 7.793334 3.96 1.96 1.124236
4 1986Q1 7.583333 7.830000 3.96 1.96 1.376948
In [128]:
us_taylor_rule_exp_quarters.to_csv('taylor_exp_quarters.csv',index=False)
In [129]:
us_taylor_rule_exp_quarters_pre_gr=us_taylor_rule_exp_quarters.loc[:91]
us_taylor_rule_exp_quarters_pre_gr.to_csv('taylor_exp_pre_gr.csv',index=False)
In [130]:
us_taylor_rule_exp_quarters_post_gr=us_taylor_rule_exp_quarters.loc[91:]
us_taylor_rule_exp_quarters_post_gr.to_csv('taylor_exp_post_gr.csv',index=False)
In [131]:
us_taylor_rule_exp_quarters_post_gr=us_taylor_rule_exp_quarters.loc[91:139]
us_taylor_rule_exp_quarters_post_gr.to_csv('taylor_exp_post_gr.csv',index=False)
In [378]:
us_output_gap=oecd_output_gap[oecd_output_gap['Country']=='United States']
us_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
us_output_gap.reset_index(drop=True,inplace=True)
us_output_gap.columns=['year','output_gap']

us_cci=oecd_cci[oecd_cci['Country']=='United States']
us_cci.drop(columns=['Country','Subject'],inplace=True)
us_cci.reset_index(drop=True,inplace=True)
us_cci.columns=['month','cci']

us_cci_year=us_cci.resample('Y',on='month').mean().reset_index()
us_cci_year['year'] = us_cci_year['month'].dt.year
us_cci_year.drop(columns='month',inplace=True)
us_cci_year=us_cci_year[['year', 'cci']]

us_cci_og=us_output_gap.merge(us_cci_year,on='year',how='inner')

plt.close()
sns.lineplot(y=us_cci_og['output_gap'],x=us_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=us_cci_og['cci'],x=us_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_cci_og.output_gap.corr(us_cci_og.cci))

us_inflation=oecd_inflation[oecd_inflation['Country']=='United States']
us_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation.reset_index(drop=True,inplace=True)
us_inflation.columns=['month','inflation']

us_cci_inflation=us_inflation.merge(us_cci,on='month',how='inner')
us_cci_inflation.inflation.corr(us_cci_inflation.cci)

plt.close()
sns.lineplot(y=us_cci_inflation['inflation'],x=us_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_inflation['cci'],x=us_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_cci_inflation.inflation.corr(us_cci_inflation.cci))

us_inflation_year=oecd_inflation_year[oecd_inflation_year['Country']=='United States']
us_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation_year.reset_index(drop=True,inplace=True)
us_inflation_year.columns=['year','inflation']

us_cci_inflation_year=us_inflation_year.merge(us_cci_year,on='year',how='inner')

plt.close()
sns.lineplot(y=us_cci_inflation_year['inflation'],x=us_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_inflation_year['cci'],x=us_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()

print('corr:',us_cci_inflation_year.inflation.corr(us_cci_inflation_year.cci))

plt.close()
sns.histplot(x=us_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(us_output_gap)

plt.close()
sns.histplot(x=us_cci['cci'],bins=20)
plt.show()
summary_stat(us_cci)

plt.close()
sns.histplot(x=us_cci_year['cci'],bins=20)
plt.show()
summary_stat(us_cci_year)

plt.close()
sns.histplot(x=us_inflation['inflation'],bins=20)
plt.show()
summary_stat(us_inflation)

plt.close()
sns.histplot(x=us_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(us_inflation_year)

us_exp_infl=pd.read_excel('US_EXP_INFL.xls',parse_dates=['Date'])
us_exp_infl=us_exp_infl[us_exp_infl['Date'].dt.month==12]
us_exp_infl['year']=us_exp_infl['Date'].dt.year
us_exp_infl.drop(columns='Date',inplace=True)
us_exp_infl.columns=['exp_inflation','year']

us_cci_exp_inflation=us_exp_infl.merge(us_cci_year,on='year',how='right')

plt.close()
sns.lineplot(y=us_cci_exp_inflation['exp_inflation'],x=us_cci_exp_inflation['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_exp_inflation['cci'],x=us_cci_exp_inflation['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()

print('corr:',us_cci_exp_inflation.exp_inflation.corr(us_cci_exp_inflation.cci))

us_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='United States']

us_interest_rate.drop(columns=['Subject','Country'],inplace=True)
us_interest_rate.reset_index(drop=True,inplace=True)
us_interest_rate.columns=['year','interest_rate']

us_taylor_rule=us_interest_rate.merge(us_inflation_year,on='year',how='inner')
us_taylor_rule['real_interest_rate']=us_taylor_rule['interest_rate']-us_taylor_rule['inflation']
us_taylor_rule['infl_dev']=us_inflation_year['inflation']-2
us_taylor_rule=us_taylor_rule.merge(us_output_gap,on='year',how='inner')
us_taylor_rule_cci=us_taylor_rule.merge(us_cci_year,on='year',how='inner')
us_taylor_rule_cci=us_taylor_rule_cci[us_taylor_rule_cci['year']<2023]
us_taylor_rule.to_csv('us_taylor.csv',index=False)

plt.close()
sns.lineplot(y=us_taylor_rule_cci['interest_rate'],x=us_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=us_taylor_rule_cci['cci'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_taylor_rule_cci['interest_rate'].corr(us_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=us_taylor_rule_cci['interest_rate'],x=us_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=us_taylor_rule_cci['output_gap'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.show()
print('corr:',us_taylor_rule_cci['interest_rate'].corr(us_taylor_rule_cci['output_gap']))

us_taylor_rule_pre_gr=us_taylor_rule[us_taylor_rule['year']<2008]
us_taylor_rule_pre_gr.to_csv('us_taylor_pre_gr.csv',index=False)

us_taylor_rule_post_gr=us_taylor_rule[(us_taylor_rule['year']<2020)&(us_taylor_rule['year']>2007)]
us_taylor_rule_post_gr.to_csv('us_taylor_post_gr.csv',index=False)

us_taylor_rule_exp=us_interest_rate.merge(us_exp_infl,on='year',how='inner')
us_taylor_rule_exp['exp_infl_dev']=us_taylor_rule_exp['exp_inflation']-2
us_taylor_rule_exp=us_taylor_rule_exp.merge(us_output_gap,on='year',how='inner')
us_taylor_rule_exp.to_csv('us_taylor_exp.csv',index=False)

us_taylor_rule_exp_pre_gr=us_taylor_rule_exp.loc[:91]
us_taylor_rule_exp_pre_gr.to_csv('us_taylor_exp_pre_gr.csv',index=False)

us_taylor_rule_exp_post_gr=us_taylor_rule_exp.loc[91:]
us_taylor_rule_exp_post_gr.to_csv('us_taylor_exp_post_gr.csv',index=False)

us_taylor_rule_exp_post_gr=us_taylor_rule_exp.loc[91:139]
us_taylor_rule_exp_post_gr.to_csv('us_taylor_exp_post_gr.csv',index=False)

plt.close()
sns.lineplot(y=us_taylor_rule_exp['exp_inflation'],x=us_taylor_rule_exp['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=us_taylor_rule_exp['interest_rate'],x=us_taylor_rule_exp['year'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',us_taylor_rule_exp['exp_inflation'].corr(us_taylor_rule_exp['interest_rate']))

us_output_gap['year']=pd.to_datetime(us_output_gap['year'],format='%Y')
us_og_quarters=us_output_gap.resample('Q',on='year').mean().reset_index()
us_og_quarters['year']=us_og_quarters['year'].dt.to_period('Q')
us_og_quarters.columns=['quarter','output_gap']
us_og_quarters['output_gap']=us_og_quarters['output_gap'].ffill()
us_og_quarters.quarter=us_og_quarters.quarter.astype(str)

us_cci_quarters=us_cci.resample('Q',on='month').mean().reset_index()
us_cci_quarters['month']=us_cci_quarters['month'].dt.to_period('Q')
us_cci_quarters.columns=['quarter','cci']
us_cci_quarters.quarter=us_cci_quarters.quarter.astype(str)

plt.close()
sns.histplot(x=us_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(us_cci_quarters)

us_inflation_quarters=oecd_inflation_quarters[oecd_inflation_quarters['Country']=='United States']
us_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation_quarters.reset_index(drop=True,inplace=True)
us_inflation_quarters.columns=['quarter','inflation']
us_inflation_quarters=us_inflation_quarters.replace('-', '',regex=True)

plt.close()
sns.histplot(x=us_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(us_inflation_quarters)

us_cci_inflation_quarters=us_inflation_quarters.merge(us_cci_quarters,on='quarter',how='inner')
us_cci_inflation_quarters.quarter=pd.to_datetime(us_cci_inflation_quarters.quarter).dt.to_period('Q')
us_cci_inflation_quarters.quarter=us_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

plt.close()
sns.lineplot(y=us_cci_inflation_quarters['inflation'],x=us_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_inflation_quarters['cci'],x=us_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()

print('corr:',us_cci_inflation_quarters.inflation.corr(us_cci_inflation_quarters.cci))

us_exp_infl_quarters=pd.read_excel('US_EXP_INFL.xls',parse_dates=['Date'])
us_exp_infl_quarters.columns=['date','exp_inflation']
us_exp_infl_quarters=us_exp_infl_quarters.resample('Q',on='date').mean().reset_index()
us_exp_infl_quarters['date']=us_exp_infl_quarters['date'].dt.to_period('Q')
us_exp_infl_quarters['exp_inflation']=us_exp_infl_quarters['exp_inflation'].ffill()
us_exp_infl_quarters.columns=['quarter','exp_inflation']
us_exp_infl_quarters.quarter=us_exp_infl_quarters.quarter.astype(str)

us_cci_exp_inflation_quarters=us_exp_infl_quarters.merge(us_cci_quarters,on='quarter',how='inner')
us_cci_exp_inflation_quarters.quarter=pd.to_datetime(us_cci_exp_inflation_quarters.quarter).dt.to_period('Q')
us_cci_exp_inflation_quarters.quarter=us_cci_exp_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

us_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='United States']
us_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
us_interest_rate_quarters.reset_index(drop=True,inplace=True)
us_interest_rate_quarters.columns=['quarter','interest_rate']
us_interest_rate_quarters=us_interest_rate_quarters.replace('-', '',regex=True)
us_interest_rate_quarters.quarter=us_interest_rate_quarters.quarter.astype(str)
us_interest_rate_quarters['prev_int_rate']=us_interest_rate_quarters['interest_rate'].shift(1)

us_taylor_rule_quarters=us_interest_rate_quarters.merge(us_inflation_quarters,on='quarter',how='inner')
us_taylor_rule_quarters['real_interest_rate']=us_taylor_rule_quarters['interest_rate']-us_taylor_rule_quarters['inflation']
us_taylor_rule_quarters['infl_dev']=us_taylor_rule_quarters['inflation']-2
us_taylor_rule_quarters=us_taylor_rule_quarters.merge(us_og_quarters,on='quarter',how='inner')
us_taylor_rule_quarters.to_csv('us_taylor_quarters.csv',index=False)

us_taylor_rule_quarters_pre_gr=us_taylor_rule_quarters.loc[0:91]
us_taylor_rule_quarters_pre_gr.to_csv('us_taylor_pre_gr.csv',index=False)

us_taylor_rule_quarters_post_gr=us_taylor_rule_quarters.loc[91:]
us_taylor_rule_quarters_post_gr.to_csv('us_taylor_post_gr.csv',index=False)

us_taylor_rule_quarters_post_gr=us_taylor_rule_quarters.loc[91:139]
us_taylor_rule_quarters_post_gr.to_csv('us_taylor_post_gr.csv',index=False)

us_taylor_rule_exp_quarters=us_interest_rate_quarters.merge(us_exp_infl_quarters,on='quarter',how='inner')
us_taylor_rule_exp_quarters['exp_infl_dev']=us_taylor_rule_exp_quarters['exp_inflation']-2
us_taylor_rule_exp_quarters=us_taylor_rule_exp_quarters.merge(us_og_quarters,on='quarter',how='inner')
us_taylor_rule_exp_quarters.quarter=pd.to_datetime(us_taylor_rule_exp_quarters.quarter).dt.to_period('Q')
us_taylor_rule_exp_quarters.quarter=us_taylor_rule_exp_quarters.quarter.dt.strftime('%Y.%q').astype(float)
us_taylor_rule_exp_quarters.to_csv('us_taylor_exp_quarters.csv',index=False)

us_taylor_rule_exp_quarters_pre_gr=us_taylor_rule_exp_quarters.loc[:91]
us_taylor_rule_exp_quarters_pre_gr.to_csv('us_taylor_exp_quart_pre_gr.csv',index=False)

us_taylor_rule_exp_quarters_post_gr=us_taylor_rule_exp_quarters.loc[91:]
us_taylor_rule_exp_quarters_post_gr.to_csv('us_taylor_exp_quart_post_gr.csv',index=False)

us_taylor_rule_exp_quarters_post_gr=us_taylor_rule_exp_quarters.loc[91:139]
us_taylor_rule_exp_quarters_post_gr.to_csv('us_taylor_exp_quart_post_gr.csv',index=False)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_cci.drop(columns=['Country','Subject'],inplace=True)
corr: 0.4609753768066784
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:25: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
corr: -0.564640654505981
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:39: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
corr: -0.5824738078085799
Period: 1985 : 2024
Observations: 40
Mean: -0.5848054885309623
Median: -0.528322093576167
Max: 3.28945657931188
Min: -4.88412437161886
Standard Deviation: 1.8851962204821073
Skewness: -0.26280969536377996
Kurtosis: -0.20600141007151374
Jarque_beraResult(statistic=0.6049571233392901, pvalue=0.7389843306793344)
Period: 1960 : 2023
Observations: 760
Mean: 99.99999948684196
Median: 100.49019999999999
Max: 102.89
Min: 96.08473
Standard Deviation: 1.4871340810746276
Skewness: -0.5386067647822662
Kurtosis: -0.5015786220939882
Jarque_beraResult(statistic=44.713896191629075, pvalue=1.9520940419681665e-10)
Period: 1960 : 2023
Observations: 64
Mean: 99.97208365885417
Median: 100.26752041666666
Max: 102.56290833333333
Min: 96.7535975
Standard Deviation: 1.4460042834958668
Skewness: -0.46745058923820165
Kurtosis: -0.6241580132555398
Jarque_beraResult(statistic=3.414731035334095, pvalue=0.18134290855320778)
Period: 1956 : 2023
Observations: 808
Mean: 3.6799915987500014
Median: 2.9566195000000004
Max: 14.75645
Min: -2.097161
Standard Deviation: 2.799998248380348
Skewness: 1.5504202510864007
Kurtosis: 2.551047434137337
Jarque_beraResult(statistic=537.6453358571944, pvalue=0.0)
Period: 1956 : 2022
Observations: 67
Mean: 3.668527161194029
Median: 2.951657
Max: 13.5492
Min: -0.3555463
Standard Deviation: 2.735816637093629
Skewness: 1.6510517797552862
Kurtosis: 2.9015515353760666
Jarque_beraResult(statistic=47.97387871875339, pvalue=3.824762728754649e-11)
corr: -0.44566605057560227
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:94: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_interest_rate.drop(columns=['Subject','Country'],inplace=True)
corr: 0.4270491504163415
corr: 0.8342417709943758
corr: 0.732819964585463
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:144: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_output_gap['year']=pd.to_datetime(us_output_gap['year'],format='%Y')
Period: 1960Q1 : 2023Q2
Observations: 254
Mean: 99.99282329396321
Median: 100.5233
Max: 102.84463333333333
Min: 96.30723333333333
Standard Deviation: 1.4837437688508814
Skewness: -0.5295755251587305
Kurtosis: -0.5294717434637022
Jarque_beraResult(statistic=14.84865337063391, pvalue=0.0005965624157220351)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:162: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
Period: 1956Q1 : 2023Q1
Observations: 269
Mean: 3.6780621439776953
Median: 2.991773
Max: 14.5056
Min: -1.62336
Standard Deviation: 2.7897800406285644
Skewness: 1.575808585397751
Kurtosis: 2.6309707614896083
Jarque_beraResult(statistic=183.5495150590166, pvalue=0.0)
corr: -0.5697632305181483
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2994433893.py:196: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
In [412]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.stats as stats

def summary_stat(var):
    try:
        print('Period:',var.iloc[0,0].year,':',var.iloc[-1,0].year)
    except:
        print('Period:',var.iloc[0,0],':',var.iloc[-1,0])
    print('Observations:',var.iloc[:,1].count())
    print('Mean:',var.iloc[:,1].mean())
    print('Median:',var.iloc[:,1].median())
    print('Max:',var.iloc[:,1].max())
    print('Min:',var.iloc[:,1].min())
    print('Standard Deviation:',var.iloc[:,1].std())
    print('Skewness:',var.iloc[:,1].skew())
    print('Kurtosis:',var.iloc[:,1].kurtosis())
    print(stats.jarque_bera(var.iloc[:,1]))

oecd_output_gap = pd.read_csv('EO_29052023144557432.csv')
oecd_output_gap.drop(columns=['LOCATION','VARIABLE','FREQUENCY','Frequency','TIME','Unit Code',
                              'PowerCode Code','PowerCode','Reference Period Code','Reference Period',
                              'Flag Codes','Flags'],inplace=True)

us_output_gap=oecd_output_gap[oecd_output_gap['Country']=='United States']
us_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
us_output_gap.reset_index(drop=True,inplace=True)
us_output_gap.columns=['year','output_gap']

oecd_cci=pd.read_csv('MEI_CLI_29052023213313302.csv',parse_dates=['TIME'])
oecd_cci.drop(columns=['SUBJECT','LOCATION','FREQUENCY','Frequency','Time','Unit Code',
                       'Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period',
                       'Flag Codes','Flags'],inplace=True)

us_cci=oecd_cci[oecd_cci['Country']=='United States']
us_cci.drop(columns=['Country','Subject'],inplace=True)
us_cci.reset_index(drop=True,inplace=True)
us_cci.columns=['month','cci']

us_cci_year=us_cci.resample('Y',on='month').mean().reset_index()
us_cci_year['year'] = us_cci_year['month'].dt.year
us_cci_year.drop(columns='month',inplace=True)
us_cci_year=us_cci_year[['year', 'cci']]

us_cci_og=us_output_gap.merge(us_cci_year,on='year',how='inner')

oecd_inflation=pd.read_csv('PRICES_CPI_08062023033246584.csv',parse_dates=['TIME'])
oecd_inflation.drop(columns=['LOCATION','SUBJECT','MEASURE','FREQUENCY','Frequency','Time','Unit Code',
                             'Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period',
                             'Flag Codes','Flags'],inplace=True)

us_inflation=oecd_inflation[oecd_inflation['Country']=='United States']
us_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation.reset_index(drop=True,inplace=True)
us_inflation.columns=['month','inflation']

us_cci_inflation=us_inflation.merge(us_cci,on='month',how='inner')
us_cci_inflation.inflation.corr(us_cci_inflation.cci)

oecd_inflation_year=pd.read_csv('PRICES_CPI_31052023125039731.csv')
oecd_inflation_year.drop(columns=['LOCATION','SUBJECT','MEASURE','FREQUENCY','Frequency','Time','Unit Code',
                                  'Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period',
                                  'Flag Codes','Flags'],inplace=True)

us_inflation_year=oecd_inflation_year[oecd_inflation_year['Country']=='United States']
us_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation_year.reset_index(drop=True,inplace=True)
us_inflation_year.columns=['year','inflation']

us_cci_inflation_year=us_inflation_year.merge(us_cci_year,on='year',how='inner')

us_exp_infl=pd.read_excel('US_EXP_INFL.xls',parse_dates=['Date'])
us_exp_infl=us_exp_infl[us_exp_infl['Date'].dt.month==12]
us_exp_infl['year']=us_exp_infl['Date'].dt.year
us_exp_infl.drop(columns='Date',inplace=True)
us_exp_infl.columns=['exp_inflation','year']

us_cci_exp_inflation=us_exp_infl.merge(us_cci_year,on='year',how='right')

oecd_interest_rate=pd.read_csv('MEI_FIN_31052023124246883.csv')
oecd_interest_rate.drop(columns=['SUBJECT','LOCATION','FREQUENCY','Frequency','Time','Unit Code',
                                 'Unit','PowerCode Code','PowerCode','Reference Period Code','Reference Period',
                                 'Flag Codes','Flags'],inplace=True)

us_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='United States']

us_interest_rate.drop(columns=['Subject','Country'],inplace=True)
us_interest_rate.reset_index(drop=True,inplace=True)
us_interest_rate.columns=['year','interest_rate']

us_taylor_rule=us_interest_rate.merge(us_inflation_year,on='year',how='inner')
us_taylor_rule['real_interest_rate']=us_taylor_rule['interest_rate']-us_taylor_rule['inflation']
us_taylor_rule['infl_dev']=us_inflation_year['inflation']-2
us_taylor_rule=us_taylor_rule.merge(us_output_gap,on='year',how='inner')
us_taylor_rule_cci=us_taylor_rule.merge(us_cci_year,on='year',how='inner')
us_taylor_rule.to_csv('us_taylor.csv',index=False)

us_taylor_rule_pre_gr=us_taylor_rule[us_taylor_rule['year']<2008]
us_taylor_rule_pre_gr.to_csv('us_taylor_pre_gr.csv',index=False)

us_taylor_rule_post_gr=us_taylor_rule[(us_taylor_rule['year']<2020)&(us_taylor_rule['year']>2007)]
us_taylor_rule_post_gr.to_csv('us_taylor_post_gr.csv',index=False)

us_taylor_rule_exp=us_interest_rate.merge(us_exp_infl,on='year',how='inner')
us_taylor_rule_exp['exp_infl_dev']=us_taylor_rule_exp['exp_inflation']-2
us_taylor_rule_exp=us_taylor_rule_exp.merge(us_output_gap,on='year',how='inner')
us_taylor_rule_exp.to_csv('us_taylor_exp.csv',index=False)

us_taylor_rule_exp_pre_gr=us_taylor_rule_exp.loc[:91]
us_taylor_rule_exp_pre_gr.to_csv('us_taylor_exp_pre_gr.csv',index=False)

us_taylor_rule_exp_post_gr=us_taylor_rule_exp.loc[91:]
us_taylor_rule_exp_post_gr.to_csv('us_taylor_exp_post_gr.csv',index=False)

us_taylor_rule_exp_post_gr=us_taylor_rule_exp.loc[91:139]
us_taylor_rule_exp_post_gr.to_csv('us_taylor_exp_post_gr.csv',index=False)

us_output_gap['year']=pd.to_datetime(us_output_gap['year'],format='%Y')
us_og_quarters=us_output_gap.resample('Q',on='year').mean().reset_index()
us_og_quarters['year']=us_og_quarters['year'].dt.to_period('Q')
us_og_quarters.columns=['quarter','output_gap']
us_og_quarters['output_gap']=us_og_quarters['output_gap'].ffill()
us_og_quarters.quarter=us_og_quarters.quarter.astype(str)

us_cci_quarters=us_cci.resample('Q',on='month').mean().reset_index()
us_cci_quarters['month']=us_cci_quarters['month'].dt.to_period('Q')
us_cci_quarters.columns=['quarter','cci']
us_cci_quarters.quarter=us_cci_quarters.quarter.astype(str)

us_inflation_quarters=oecd_inflation_quarters[oecd_inflation_quarters['Country']=='United States']
us_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
us_inflation_quarters.reset_index(drop=True,inplace=True)
us_inflation_quarters.columns=['quarter','inflation']
us_inflation_quarters=us_inflation_quarters.replace('-', '',regex=True)

us_cci_inflation_quarters=us_inflation_quarters.merge(us_cci_quarters,on='quarter',how='inner')
us_cci_inflation_quarters.quarter=pd.to_datetime(us_cci_inflation_quarters.quarter).dt.to_period('Q')
us_cci_inflation_quarters.quarter=us_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

us_exp_infl_quarters=pd.read_excel('US_EXP_INFL.xls',parse_dates=['Date'])
us_exp_infl_quarters.columns=['date','exp_inflation']
us_exp_infl_quarters=us_exp_infl_quarters.resample('Q',on='date').mean().reset_index()
us_exp_infl_quarters['date']=us_exp_infl_quarters['date'].dt.to_period('Q')
us_exp_infl_quarters['exp_inflation']=us_exp_infl_quarters['exp_inflation'].ffill()
us_exp_infl_quarters.columns=['quarter','exp_inflation']
us_exp_infl_quarters.quarter=us_exp_infl_quarters.quarter.astype(str)

us_cci_exp_inflation_quarters=us_exp_infl_quarters.merge(us_cci_quarters,on='quarter',how='inner')
us_cci_exp_inflation_quarters.quarter=pd.to_datetime(us_cci_exp_inflation_quarters.quarter).dt.to_period('Q')
us_cci_exp_inflation_quarters.quarter=us_cci_exp_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

us_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='United States']
us_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
us_interest_rate_quarters.reset_index(drop=True,inplace=True)
us_interest_rate_quarters.columns=['quarter','interest_rate']
us_interest_rate_quarters=us_interest_rate_quarters.replace('-', '',regex=True)
us_interest_rate_quarters.quarter=us_interest_rate_quarters.quarter.astype(str)
us_interest_rate_quarters['prev_int_rate']=us_interest_rate_quarters['interest_rate'].shift(1)

us_taylor_rule_quarters=us_interest_rate_quarters.merge(us_inflation_quarters,on='quarter',how='inner')
us_taylor_rule_quarters['real_interest_rate']=us_taylor_rule_quarters['interest_rate']-us_taylor_rule_quarters['inflation']
us_taylor_rule_quarters['infl_dev']=us_taylor_rule_quarters['inflation']-2
us_taylor_rule_quarters=us_taylor_rule_quarters.merge(us_og_quarters,on='quarter',how='inner')
us_taylor_rule_cci_quarters=us_taylor_rule_quarters.merge(us_cci_quarters,on='quarter',how='inner')
us_taylor_rule_cci_quarters.quarter=pd.to_datetime(us_taylor_rule_cci_quarters.quarter).dt.to_period('Q')
us_taylor_rule_cci_quarters.quarter=us_taylor_rule_cci_quarters.quarter.dt.strftime('%Y.%q').astype(float)
us_taylor_rule_quarters.to_csv('us_taylor_quarters.csv',index=False)

us_taylor_rule_quarters_pre_gr=us_taylor_rule_quarters.loc[0:91]
us_taylor_rule_quarters_pre_gr.to_csv('us_taylor_quart_pre_gr.csv',index=False)

us_taylor_rule_quarters_post_gr=us_taylor_rule_quarters.loc[91:139]
us_taylor_rule_quarters_post_gr.to_csv('us_taylor_quart_post_gr.csv',index=False)

us_taylor_rule_exp_quarters=us_interest_rate_quarters.merge(us_exp_infl_quarters,on='quarter',how='inner')
us_taylor_rule_exp_quarters['exp_infl_dev']=us_taylor_rule_exp_quarters['exp_inflation']-2
us_taylor_rule_exp_quarters=us_taylor_rule_exp_quarters.merge(us_og_quarters,on='quarter',how='inner')
us_taylor_rule_exp_quarters.quarter=pd.to_datetime(us_taylor_rule_exp_quarters.quarter).dt.to_period('Q')
us_taylor_rule_exp_quarters.quarter=us_taylor_rule_exp_quarters.quarter.dt.strftime('%Y.%q').astype(float)
us_taylor_rule_exp_quarters.to_csv('us_taylor_exp_quarters.csv',index=False)

us_taylor_rule_exp_quarters_pre_gr=us_taylor_rule_exp_quarters.loc[:91]
us_taylor_rule_exp_quarters_pre_gr.to_csv('us_taylor_exp_quart_pre_gr.csv',index=False)

us_taylor_rule_exp_quarters_post_gr=us_taylor_rule_exp_quarters.loc[91:139]
us_taylor_rule_exp_quarters_post_gr.to_csv('us_taylor_exp_quart_post_gr.csv',index=False)

plt.close()
sns.histplot(x=us_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(us_output_gap)

plt.close()
sns.histplot(x=us_cci['cci'],bins=20)
plt.show()
summary_stat(us_cci)

plt.close()
sns.histplot(x=us_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(us_cci_quarters)

plt.close()
sns.histplot(x=us_cci_year['cci'],bins=20)
plt.show()
summary_stat(us_cci_year)

plt.close()
sns.histplot(x=us_inflation['inflation'],bins=20)
plt.show()
summary_stat(us_inflation)

plt.close()
sns.histplot(x=us_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(us_inflation_quarters)

plt.close()
sns.histplot(x=us_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(us_inflation_year)

plt.close()
sns.lineplot(y=us_cci_og['output_gap'],x=us_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=us_cci_og['cci'],x=us_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_cci_og.output_gap.corr(us_cci_og.cci))

plt.close()
sns.lineplot(y=us_cci_inflation['inflation'],x=us_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_inflation['cci'],x=us_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_cci_inflation.inflation.corr(us_cci_inflation.cci))

plt.close()
sns.lineplot(y=us_cci_inflation_quarters['inflation'],x=us_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_inflation_quarters['cci'],x=us_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_cci_inflation_quarters.inflation.corr(us_cci_inflation_quarters.cci))

plt.close()
sns.lineplot(y=us_cci_inflation_year['inflation'],x=us_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_inflation_year['cci'],x=us_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_cci_inflation_year.inflation.corr(us_cci_inflation_year.cci))

plt.close()
sns.lineplot(y=us_cci_exp_inflation['exp_inflation'],x=us_cci_exp_inflation['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=us_cci_exp_inflation['cci'],x=us_cci_exp_inflation['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_cci_exp_inflation.exp_inflation.corr(us_cci_exp_inflation.cci))

plt.close()
sns.lineplot(y=us_taylor_rule_cci_quarters['interest_rate'],x=us_taylor_rule_cci_quarters['quarter'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=us_taylor_rule_cci_quarters['cci'],x=us_taylor_rule_cci_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_taylor_rule_cci_quarters['interest_rate'].corr(us_taylor_rule_cci_quarters['cci']))

plt.close()
sns.lineplot(y=us_taylor_rule_cci['interest_rate'],x=us_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=us_taylor_rule_cci['cci'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',us_taylor_rule_cci['interest_rate'].corr(us_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=us_taylor_rule_cci['interest_rate'],x=us_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=us_taylor_rule_cci['output_gap'],x=us_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.show()
print('corr:',us_taylor_rule_cci['interest_rate'].corr(us_taylor_rule_cci['output_gap']))

plt.close()
sns.lineplot(y=us_taylor_rule_exp['exp_inflation'],x=us_taylor_rule_exp['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=us_taylor_rule_exp['interest_rate'],x=us_taylor_rule_exp['year'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',us_taylor_rule_exp['exp_inflation'].corr(us_taylor_rule_exp['interest_rate']))
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:27: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:37: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:54: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:67: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:88: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_interest_rate.drop(columns=['Subject','Country'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:119: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_output_gap['year']=pd.to_datetime(us_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:132: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/471838391.py:154: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  us_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Period: 1985 : 2024
Observations: 40
Mean: -0.5848054885309623
Median: -0.528322093576167
Max: 3.28945657931188
Min: -4.88412437161886
Standard Deviation: 1.8851962204821073
Skewness: -0.26280969536377996
Kurtosis: -0.20600141007151374
Jarque_beraResult(statistic=0.6049571233392901, pvalue=0.7389843306793344)
Period: 1960 : 2023
Observations: 760
Mean: 99.99999948684196
Median: 100.49019999999999
Max: 102.89
Min: 96.08473
Standard Deviation: 1.4871340810746276
Skewness: -0.5386067647822662
Kurtosis: -0.5015786220939882
Jarque_beraResult(statistic=44.713896191629075, pvalue=1.9520940419681665e-10)
Period: 1960Q1 : 2023Q2
Observations: 254
Mean: 99.99282329396321
Median: 100.5233
Max: 102.84463333333333
Min: 96.30723333333333
Standard Deviation: 1.4837437688508814
Skewness: -0.5295755251587305
Kurtosis: -0.5294717434637022
Jarque_beraResult(statistic=14.84865337063391, pvalue=0.0005965624157220351)
Period: 1960 : 2023
Observations: 64
Mean: 99.97208365885417
Median: 100.26752041666666
Max: 102.56290833333333
Min: 96.7535975
Standard Deviation: 1.4460042834958668
Skewness: -0.46745058923820165
Kurtosis: -0.6241580132555398
Jarque_beraResult(statistic=3.414731035334095, pvalue=0.18134290855320778)
Period: 1956 : 2023
Observations: 808
Mean: 3.6799915987500014
Median: 2.9566195000000004
Max: 14.75645
Min: -2.097161
Standard Deviation: 2.799998248380348
Skewness: 1.5504202510864007
Kurtosis: 2.551047434137337
Jarque_beraResult(statistic=537.6453358571944, pvalue=0.0)
Period: 1956Q1 : 2023Q1
Observations: 269
Mean: 3.6780621439776953
Median: 2.991773
Max: 14.5056
Min: -1.62336
Standard Deviation: 2.7897800406285644
Skewness: 1.575808585397751
Kurtosis: 2.6309707614896083
Jarque_beraResult(statistic=183.5495150590166, pvalue=0.0)
Period: 1956 : 2022
Observations: 67
Mean: 3.668527161194029
Median: 2.951657
Max: 13.5492
Min: -0.3555463
Standard Deviation: 2.735816637093629
Skewness: 1.6510517797552862
Kurtosis: 2.9015515353760666
Jarque_beraResult(statistic=47.97387871875339, pvalue=3.824762728754649e-11)
corr: 0.4609753768066784
corr: -0.564640654505981
corr: -0.5697632305181483
corr: -0.5824738078085799
corr: -0.44566605057560227
corr: 0.3953509341086551
corr: 0.4270491504163415
corr: 0.8342417709943758
corr: 0.732819964585463

Expected Inflation EUR¶

In [140]:
eur_exp_infl=pd.read_csv('ECB Data Portal/ECB Data Portal annual_20230530023013.csv')
eur_exp_infl.drop(columns=['DATE'],inplace=True)
eur_exp_infl.columns=['year','exp_inflation','exp_infl_2y']
eur_exp_infl.head()
Out[140]:
year exp_inflation exp_infl_2y
0 1999 1.00 NaN
1 2000 1.75 1.33
2 2001 2.00 1.68
3 2002 1.69 1.72
4 2003 1.84 1.78
In [142]:
eur_exp_infl_quarters=pd.read_csv('ECB Data Portal/ECB Data Portal monthly_20230530023013.csv',parse_dates=['DATE'])
eur_exp_infl_quarters.drop(columns=['TIME PERIOD'],inplace=True)
eur_exp_infl_quarters.head()
Out[142]:
DATE Euro area - HICP Inflation - Average of Point forecasts - Target period ends 12 months after survey cycle begins (SPF.M.U2.HICP.POINT.P12M.Q.AVG) Euro area - HICP Inflation - Average of Point forecasts - Target period ends 24 months after survey cycle begins (SPF.M.U2.HICP.POINT.P24M.Q.AVG)
0 1999-12-31 1.15 NaN
1 2000-03-31 1.46 NaN
2 2000-06-30 1.49 NaN
3 2000-09-30 1.52 NaN
4 2000-12-31 1.64 1.5
In [144]:
eur_exp_infl_quarters=pd.read_csv('ECB Data Portal/ECB Data Portal monthly_20230530023013.csv',parse_dates=['DATE'])
eur_exp_infl_quarters.drop(columns=['TIME PERIOD'],inplace=True)
eur_exp_infl_quarters.columns=['date','exp_inflation','exp_infl_2y']
eur_exp_infl_quarters=eur_exp_infl_quarters.resample('Q',on='date').mean().reset_index()
eur_exp_infl_quarters['date']=eur_exp_infl_quarters['date'].dt.to_period('Q')
eur_exp_infl_quarters['exp_inflation']=eur_exp_infl_quarters['exp_inflation'].ffill()
eur_exp_infl_quarters.columns=['quarter','exp_inflation','exp_infl_2y']
eur_exp_infl_quarters.quarter=eur_exp_infl_quarters.quarter.astype(str)
eur_exp_infl_quarters.head()
Out[144]:
quarter exp_inflation exp_infl_2y
0 1999Q4 1.15 NaN
1 2000Q1 1.46 NaN
2 2000Q2 1.49 NaN
3 2000Q3 1.52 NaN
4 2000Q4 1.64 1.5

Germany¶

In [421]:
ger_output_gap=oecd_output_gap[oecd_output_gap['Country']=='Germany']
ger_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
ger_output_gap.reset_index(drop=True,inplace=True)
ger_output_gap.columns=['year','output_gap']

ger_cci=oecd_cci[oecd_cci['Country']=='Germany']
ger_cci.drop(columns=['Country','Subject'],inplace=True)
ger_cci.reset_index(drop=True,inplace=True)
ger_cci.columns=['month','cci']

ger_cci_year=ger_cci.resample('Y',on='month').mean().reset_index()
ger_cci_year['year'] = ger_cci_year['month'].dt.year
ger_cci_year.drop(columns='month',inplace=True)
ger_cci_year=ger_cci_year[['year', 'cci']]

ger_cci_og=ger_output_gap.merge(ger_cci_year,on='year',how='inner')

ger_inflation=oecd_hicp[oecd_hicp['Country']=='Germany']
ger_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
ger_inflation.reset_index(drop=True,inplace=True)
ger_inflation.columns=['month','inflation']

ger_cci_inflation=ger_inflation.merge(ger_cci,on='month',how='inner')

ger_inflation_year=oecd_hicp_year[oecd_hicp_year['Country']=='Germany']
ger_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
ger_inflation_year.reset_index(drop=True,inplace=True)
ger_inflation_year.columns=['year','inflation']

ger_cci_inflation_year=ger_inflation_year.merge(ger_cci_year,on='year',how='inner')

ger_cci_exp_inflation=eur_exp_infl.merge(ger_cci_year,on='year',how='inner')

ger_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='Germany']

ger_interest_rate.drop(columns=['Subject','Country'],inplace=True)
ger_interest_rate.reset_index(drop=True,inplace=True)
ger_interest_rate.columns=['year','interest_rate']

ger_taylor_rule=ger_interest_rate.merge(ger_inflation_year,on='year',how='inner')
ger_taylor_rule['real_interest_rate']=ger_taylor_rule['interest_rate']-ger_taylor_rule['inflation']
ger_taylor_rule['infl_dev']=ger_inflation_year['inflation']-2
ger_taylor_rule=ger_taylor_rule.merge(ger_output_gap,on='year',how='inner')
ger_taylor_rule_cci=ger_taylor_rule.merge(ger_cci_year,on='year',how='inner')
ger_taylor_rule_cci=ger_taylor_rule_cci[ger_taylor_rule_cci['year']<2023]
ger_taylor_rule.to_csv('ger_taylor.csv',index=False)
ger_taylor_rule_pre_gr=ger_taylor_rule[ger_taylor_rule['year']<2008]
ger_taylor_rule_pre_gr.to_csv('ger_taylor_pre_gr.csv',index=False)

ger_taylor_rule_post_gr=ger_taylor_rule[(ger_taylor_rule['year']<2020)&(ger_taylor_rule['year']>2007)]
ger_taylor_rule_post_gr.to_csv('ger_taylor_post_gr.csv',index=False)

ger_taylor_rule_exp=ger_interest_rate.merge(eur_exp_infl,on='year',how='inner')
ger_taylor_rule_exp['exp_infl_dev']=ger_taylor_rule_exp['exp_inflation']-2
ger_taylor_rule_exp=ger_taylor_rule_exp.merge(ger_output_gap,on='year',how='inner')
ger_taylor_rule_exp.to_csv('ger_taylor_exp.csv',index=False)

ger_taylor_rule_exp_pre_gr=ger_taylor_rule_exp.loc[:91]
ger_taylor_rule_exp_pre_gr.to_csv('ger_taylor_exp_pre_gr.csv',index=False)

ger_taylor_rule_exp_post_gr=ger_taylor_rule_exp.loc[91:]
ger_taylor_rule_exp_post_gr.to_csv('ger_taylor_exp_post_gr.csv',index=False)

ger_output_gap['year']=pd.to_datetime(ger_output_gap['year'],format='%Y')
ger_og_quarters=ger_output_gap.resample('Q',on='year').mean().reset_index()
ger_og_quarters['year']=ger_og_quarters['year'].dt.to_period('Q')
ger_og_quarters.columns=['quarter','output_gap']
ger_og_quarters['output_gap']=ger_og_quarters['output_gap'].ffill()
ger_og_quarters.quarter=ger_og_quarters.quarter.astype(str)

ger_cci_quarters=ger_cci.resample('Q',on='month').mean().reset_index()
ger_cci_quarters['month']=ger_cci_quarters['month'].dt.to_period('Q')
ger_cci_quarters.columns=['quarter','cci']
ger_cci_quarters.quarter=ger_cci_quarters.quarter.astype(str)

ger_inflation_quarters=ger_inflation.resample('Q',on='month').mean().reset_index()
ger_inflation_quarters['month']=ger_inflation_quarters['month'].dt.to_period('Q')
ger_inflation_quarters.columns=['quarter','inflation']
ger_inflation_quarters.quarter=ger_inflation_quarters.quarter.astype(str)

ger_cci_inflation_quarters=ger_inflation_quarters.merge(ger_cci_quarters,on='quarter',how='inner')
ger_cci_inflation_quarters.quarter=pd.to_datetime(ger_cci_inflation_quarters.quarter).dt.to_period('Q')
ger_cci_inflation_quarters.quarter=ger_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

ger_cci_exp_inflation_quarters=eur_exp_infl_quarters.merge(ger_cci_quarters,on='quarter',how='inner')
ger_cci_exp_inflation_quarters.quarter=pd.to_datetime(ger_cci_exp_inflation_quarters.quarter).dt.to_period('Q')
ger_cci_exp_inflation_quarters.quarter=ger_cci_exp_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

ger_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='Germany']
ger_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
ger_interest_rate_quarters.reset_index(drop=True,inplace=True)
ger_interest_rate_quarters.columns=['quarter','interest_rate']
ger_interest_rate_quarters=ger_interest_rate_quarters.replace('-', '',regex=True)
ger_interest_rate_quarters.quarter=ger_interest_rate_quarters.quarter.astype(str)
ger_interest_rate_quarters['prev_int_rate']=ger_interest_rate_quarters['interest_rate'].shift(1)

ger_taylor_rule_quarters=ger_interest_rate_quarters.merge(ger_inflation_quarters,on='quarter',how='inner')
ger_taylor_rule_quarters['real_interest_rate']=ger_taylor_rule_quarters['interest_rate']-ger_taylor_rule_quarters['inflation']
ger_taylor_rule_quarters['infl_dev']=ger_taylor_rule_quarters['inflation']-2
ger_taylor_rule_quarters=ger_taylor_rule_quarters.merge(ger_og_quarters,on='quarter',how='inner')
ger_taylor_rule_cci_quarters=ger_taylor_rule_quarters.merge(ger_cci_quarters,on='quarter',how='inner')
ger_taylor_rule_cci_quarters.quarter=pd.to_datetime(ger_taylor_rule_cci_quarters.quarter).dt.to_period('Q')
ger_taylor_rule_cci_quarters.quarter=ger_taylor_rule_cci_quarters.quarter.dt.strftime('%Y.%q').astype(float)
ger_taylor_rule_quarters.to_csv('ger_taylor_quarters.csv',index=False)

ger_taylor_rule_quarters_pre_gr=ger_taylor_rule_quarters.loc[:47]
ger_taylor_rule_quarters_pre_gr.to_csv('ger_taylor_quart_pre_gr.csv',index=False)

ger_taylor_rule_quarters_post_gr=ger_taylor_rule_quarters.loc[48:91]
ger_taylor_rule_quarters_post_gr.to_csv('ger_taylor_quart_post_gr.csv',index=False)

ger_taylor_rule_exp_quarters=ger_interest_rate_quarters.merge(eur_exp_infl_quarters,on='quarter',how='inner')
ger_taylor_rule_exp_quarters['exp_infl_dev']=ger_taylor_rule_exp_quarters['exp_inflation']-2
ger_taylor_rule_exp_quarters=ger_taylor_rule_exp_quarters.merge(ger_og_quarters,on='quarter',how='inner')
ger_taylor_rule_exp_quarters.quarter=pd.to_datetime(ger_taylor_rule_exp_quarters.quarter).dt.to_period('Q')
ger_taylor_rule_exp_quarters.quarter=ger_taylor_rule_exp_quarters.quarter.dt.strftime('%Y.%q').astype(float)
ger_taylor_rule_exp_quarters.to_csv('ger_taylor_exp_quarters.csv',index=False)

ger_taylor_rule_exp_quarters_pre_gr=ger_taylor_rule_exp_quarters.loc[:47]
ger_taylor_rule_exp_quarters_pre_gr.to_csv('ger_taylor_exp_quart_pre_gr.csv',index=False)

ger_taylor_rule_exp_quarters_post_gr=ger_taylor_rule_exp_quarters.loc[48:91]
ger_taylor_rule_exp_quarters_post_gr.to_csv('ger_taylor_exp_quart_post_gr.csv',index=False)

plt.close()
sns.histplot(x=ger_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(ger_output_gap)

plt.close()
sns.histplot(x=ger_cci['cci'],bins=20)
plt.show()
summary_stat(ger_cci)

plt.close()
sns.histplot(x=ger_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(ger_cci_quarters)

plt.close()
sns.histplot(x=ger_cci_year['cci'],bins=20)
plt.show()
summary_stat(ger_cci_year)

plt.close()
sns.histplot(x=ger_inflation['inflation'],bins=20)
plt.show()
summary_stat(ger_inflation)

plt.close()
sns.histplot(x=ger_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(ger_inflation_quarters)

plt.close()
sns.histplot(x=ger_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(ger_inflation_year)

plt.close()
sns.lineplot(y=ger_cci_og['output_gap'],x=ger_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=ger_cci_og['cci'],x=ger_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_cci_og.output_gap.corr(ger_cci_og.cci))

plt.close()
sns.lineplot(y=ger_cci_inflation['inflation'],x=ger_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=ger_cci_inflation['cci'],x=ger_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_cci_inflation.inflation.corr(ger_cci_inflation.cci))

plt.close()
sns.lineplot(y=ger_cci_inflation_quarters['inflation'],x=ger_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=ger_cci_inflation_quarters['cci'],x=ger_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_cci_inflation_quarters.inflation.corr(ger_cci_inflation_quarters.cci))

plt.close()
sns.lineplot(y=ger_cci_inflation_year['inflation'],x=ger_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=ger_cci_inflation_year['cci'],x=ger_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_cci_inflation_year.inflation.corr(ger_cci_inflation_year.cci))

plt.close()
sns.lineplot(y=ger_cci_exp_inflation_quarters['exp_inflation'],x=ger_cci_exp_inflation_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ger_cci_exp_inflation_quarters['cci'],x=ger_cci_exp_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_cci_exp_inflation_quarters.exp_inflation.corr(ger_cci_exp_inflation_quarters.cci))

plt.close()
sns.lineplot(y=ger_cci_exp_inflation['exp_inflation'],x=ger_cci_exp_inflation['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ger_cci_exp_inflation['cci'],x=ger_cci_exp_inflation['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_cci_exp_inflation.exp_inflation.corr(ger_cci_exp_inflation.cci))

plt.close()
sns.lineplot(y=ger_taylor_rule_cci_quarters['interest_rate'],x=ger_taylor_rule_cci_quarters['quarter'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=ger_taylor_rule_cci_quarters['cci'],x=ger_taylor_rule_cci_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_taylor_rule_cci_quarters['interest_rate'].corr(ger_taylor_rule_cci_quarters['cci']))

plt.close()
sns.lineplot(y=ger_taylor_rule_cci['interest_rate'],x=ger_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=ger_taylor_rule_cci['cci'],x=ger_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ger_taylor_rule_cci['interest_rate'].corr(ger_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=ger_taylor_rule_cci['interest_rate'],x=ger_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=ger_taylor_rule_cci['output_gap'],x=ger_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.show()
print('corr:',ger_taylor_rule_cci['interest_rate'].corr(ger_taylor_rule_cci['output_gap']))

plt.close()
sns.lineplot(y=ger_taylor_rule_exp_quarters['exp_inflation'],x=ger_taylor_rule_exp_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ger_taylor_rule_exp_quarters['interest_rate'],x=ger_taylor_rule_exp_quarters['quarter'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',ger_taylor_rule_exp_quarters['exp_inflation'].corr(ger_taylor_rule_exp_quarters['interest_rate']))

plt.close()
sns.lineplot(y=ger_taylor_rule_exp['exp_inflation'],x=ger_taylor_rule_exp['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ger_taylor_rule_exp['interest_rate'],x=ger_taylor_rule_exp['year'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',ger_taylor_rule_exp['exp_inflation'].corr(ger_taylor_rule_exp['interest_rate']))
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1567089075.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ger_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1567089075.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ger_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1567089075.py:19: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ger_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1567089075.py:26: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ger_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1567089075.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ger_interest_rate.drop(columns=['Subject','Country'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1567089075.py:64: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ger_output_gap['year']=pd.to_datetime(ger_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/1567089075.py:90: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ger_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Period: 1991 : 2024
Observations: 34
Mean: -0.32236490451375727
Median: -0.3332641621099365
Max: 3.48937708760628
Min: -4.65642185040223
Standard Deviation: 1.7955417880622324
Skewness: -0.11849649288708826
Kurtosis: -0.037320655757196786
Jarque_beraResult(statistic=0.13127541292308398, pvalue=0.9364700798990038)
Period: 1973 : 2023
Observations: 604
Mean: 100.0000008278146
Median: 100.18825
Max: 103.7203
Min: 95.8793
Standard Deviation: 1.5815997305661775
Skewness: -0.39205690787477226
Kurtosis: -0.25828740770760916
Jarque_beraResult(statistic=17.17817354334823, pvalue=0.0001861259855877595)
Period: 1973Q1 : 2023Q2
Observations: 202
Mean: 99.99650762376245
Median: 100.17157
Max: 103.54506666666667
Min: 96.01001333333333
Standard Deviation: 1.572358082943885
Skewness: -0.385355894051372
Kurtosis: -0.27259373861143743
Jarque_beraResult(statistic=5.660040292408981, pvalue=0.05901166479640596)
Period: 1973 : 2023
Observations: 51
Mean: 99.978986372549
Median: 100.11982833333333
Max: 102.70249166666667
Min: 96.51100416666667
Standard Deviation: 1.4954389425271972
Skewness: -0.364861111652172
Kurtosis: -0.380129906866955
Jarque_beraResult(statistic=1.513629403740023, pvalue=0.46915845902719144)
Period: 1997 : 2023
Observations: 317
Mean: 1.8536277602523663
Median: 1.5
Max: 11.6
Min: -0.7
Standard Deviation: 1.8597913385711842
Skewness: 2.8838981649433615
Kurtosis: 9.90594659352549
Jarque_beraResult(statistic=1686.116288820403, pvalue=0.0)
Period: 1997Q1 : 2023Q2
Observations: 106
Mean: 1.8696540880503139
Median: 1.5666666666666667
Max: 10.833333333333334
Min: -0.6333333333333333
Standard Deviation: 1.8603362004423423
Skewness: 2.8504851035191097
Kurtosis: 9.469958140076487
Jarque_beraResult(statistic=495.1071240459648, pvalue=0.0)
Period: 1996 : 2022
Observations: 27
Mean: 1.7185185185185188
Median: 1.5
Max: 8.7
Min: 0.2
Standard Deviation: 1.5935053370664496
Skewness: 3.3965914078340314
Kurtosis: 14.662867001774853
Jarque_beraResult(statistic=204.7435139832068, pvalue=0.0)
corr: 0.44211520237026114
corr: -0.30251239071005553
corr: -0.3091354796648426
corr: -0.2469895743570168
corr: -0.43879300380265285
corr: -0.466939170781212
corr: -0.40690058784303423
corr: -0.4535084858946735
corr: 0.2819615466655948
corr: 0.5823922831611823
corr: 0.44884012539410645
In [417]:
ger_taylor_rule_quarters.loc[47:91]
Out[417]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
47 2008Q4 4.214667 4.981800 1.700000 2.514667 -0.300000 2.044873
48 2009Q1 2.011700 4.214667 0.800000 1.211700 -1.200000 -4.656422
49 2009Q2 1.310633 2.011700 0.200000 1.110633 -1.800000 -4.656422
50 2009Q3 0.869200 1.310633 -0.366667 1.235867 -2.366667 -4.656422
51 2009Q4 0.721900 0.869200 0.366667 0.355233 -1.633333 -4.656422
52 2010Q1 0.662133 0.721900 0.766667 -0.104533 -1.233333 -1.735759
53 2010Q2 0.686267 0.662133 1.033333 -0.347067 -0.966667 -1.735759
54 2010Q3 0.874933 0.686267 1.133333 -0.258400 -0.866667 -1.735759
55 2010Q4 1.020467 0.874933 1.533333 -0.512866 -0.466667 -1.735759
56 2011Q1 1.093133 1.020467 2.233333 -1.140200 0.233333 0.990448
57 2011Q2 1.411633 1.093133 2.533333 -1.121700 0.533333 0.990448
58 2011Q3 1.562067 1.411633 2.633333 -1.071266 0.633333 0.990448
59 2011Q4 1.495567 1.562067 2.566667 -1.071100 0.566667 0.990448
60 2012Q1 1.043000 1.495567 2.433333 -1.390333 0.433333 0.295490
61 2012Q2 0.696033 1.043000 2.066667 -1.370633 0.066667 0.295490
62 2012Q3 0.358567 0.696033 2.133333 -1.774767 0.133333 0.295490
63 2012Q4 0.195133 0.358567 2.033333 -1.838200 0.033333 0.295490
64 2013Q1 0.211467 0.195133 1.866667 -1.655200 -0.133333 -0.520889
65 2013Q2 0.206800 0.211467 1.533333 -1.326533 -0.466667 -0.520889
66 2013Q3 0.223500 0.206800 1.666667 -1.443167 -0.333333 -0.520889
67 2013Q4 0.240900 0.223500 1.333333 -1.092433 -0.666667 -0.520889
68 2014Q1 0.295133 0.240900 0.933333 -0.638200 -1.066667 0.138701
69 2014Q2 0.298567 0.295133 0.900000 -0.601433 -1.100000 0.138701
70 2014Q3 0.164567 0.298567 0.766667 -0.602100 -1.233333 0.138701
71 2014Q4 0.081467 0.164567 0.433333 -0.351867 -1.566667 0.138701
72 2015Q1 0.046033 0.081467 -0.133333 0.179367 -2.133333 -0.242994
73 2015Q2 -0.006533 0.046033 1.233333 -1.239867 -0.766667 -0.242994
74 2015Q3 -0.027800 -0.006533 1.066667 -1.094467 -0.933333 -0.242994
75 2015Q4 -0.089167 -0.027800 0.533333 -0.622500 -1.466667 -0.242994
76 2016Q1 -0.186067 -0.089167 0.133333 -0.319400 -1.866667 0.263056
77 2016Q2 -0.258100 -0.186067 -0.100000 -0.158100 -2.100000 0.263056
78 2016Q3 -0.298100 -0.258100 0.400000 -0.698100 -1.600000 0.263056
79 2016Q4 -0.312500 -0.298100 1.033333 -1.345833 -0.966667 0.263056
80 2017Q1 -0.327800 -0.312500 1.766667 -2.094467 -0.233333 1.750724
81 2017Q2 -0.329967 -0.327800 1.666667 -1.996633 -0.333333 1.750724
82 2017Q3 -0.329633 -0.329967 1.833333 -2.162967 -0.166667 1.750724
83 2017Q4 -0.328800 -0.329633 1.566667 -1.895467 -0.433333 1.750724
84 2018Q1 -0.328300 -0.328800 1.466667 -1.794967 -0.533333 1.441587
85 2018Q2 -0.325233 -0.328300 1.966667 -2.291900 -0.033333 1.441587
86 2018Q3 -0.319500 -0.325233 2.166667 -2.486167 0.166667 1.441587
87 2018Q4 -0.315333 -0.319500 2.166667 -2.482000 0.166667 1.441587
88 2019Q1 -0.308533 -0.315333 1.600000 -1.908533 -0.400000 1.361443
89 2019Q2 -0.317100 -0.308533 1.633333 -1.950433 -0.366667 1.361443
90 2019Q3 -0.396733 -0.317100 1.000000 -1.396733 -1.000000 1.361443
91 2019Q4 -0.402967 -0.396733 1.200000 -1.602967 -0.800000 1.361443

France¶

In [422]:
fr_output_gap=oecd_output_gap[oecd_output_gap['Country']=='France']
fr_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
fr_output_gap.reset_index(drop=True,inplace=True)
fr_output_gap.columns=['year','output_gap']

fr_cci=oecd_cci[oecd_cci['Country']=='France']
fr_cci.drop(columns=['Country','Subject'],inplace=True)
fr_cci.reset_index(drop=True,inplace=True)
fr_cci.columns=['month','cci']

fr_cci_year=fr_cci.resample('Y',on='month').mean().reset_index()
fr_cci_year['year'] = fr_cci_year['month'].dt.year
fr_cci_year.drop(columns='month',inplace=True)
fr_cci_year=fr_cci_year[['year', 'cci']]

fr_cci_og=fr_output_gap.merge(fr_cci_year,on='year',how='inner')

fr_inflation=oecd_hicp[oecd_hicp['Country']=='France']
fr_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
fr_inflation.reset_index(drop=True,inplace=True)
fr_inflation.columns=['month','inflation']

fr_cci_inflation=fr_inflation.merge(fr_cci,on='month',how='inner')

fr_inflation_year=oecd_hicp_year[oecd_hicp_year['Country']=='France']
fr_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
fr_inflation_year.reset_index(drop=True,inplace=True)
fr_inflation_year.columns=['year','inflation']

fr_cci_inflation_year=fr_inflation_year.merge(fr_cci_year,on='year',how='inner')

fr_cci_exp_inflation=eur_exp_infl.merge(fr_cci_year,on='year',how='inner')

fr_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='France']

fr_interest_rate.drop(columns=['Subject','Country'],inplace=True)
fr_interest_rate.reset_index(drop=True,inplace=True)
fr_interest_rate.columns=['year','interest_rate']

fr_taylor_rule=fr_interest_rate.merge(fr_inflation_year,on='year',how='inner')
fr_taylor_rule['real_interest_rate']=fr_taylor_rule['interest_rate']-fr_taylor_rule['inflation']
fr_taylor_rule['infl_dev']=fr_inflation_year['inflation']-2
fr_taylor_rule=fr_taylor_rule.merge(fr_output_gap,on='year',how='inner')
fr_taylor_rule_cci=fr_taylor_rule.merge(fr_cci_year,on='year',how='inner')
fr_taylor_rule_cci=fr_taylor_rule_cci[fr_taylor_rule_cci['year']<2023]
fr_taylor_rule.to_csv('fr_taylor.csv',index=False)
fr_taylor_rule_pre_gr=fr_taylor_rule[fr_taylor_rule['year']<2008]
fr_taylor_rule_pre_gr.to_csv('fr_taylor_pre_gr.csv',index=False)

fr_taylor_rule_post_gr=fr_taylor_rule[(fr_taylor_rule['year']<2020)&(fr_taylor_rule['year']>2007)]
fr_taylor_rule_post_gr.to_csv('fr_taylor_post_gr.csv',index=False)

fr_taylor_rule_exp=fr_interest_rate.merge(eur_exp_infl,on='year',how='inner')
fr_taylor_rule_exp['exp_infl_dev']=fr_taylor_rule_exp['exp_inflation']-2
fr_taylor_rule_exp=fr_taylor_rule_exp.merge(fr_output_gap,on='year',how='inner')
fr_taylor_rule_exp.to_csv('fr_taylor_exp.csv',index=False)

fr_taylor_rule_exp_pre_gr=fr_taylor_rule_exp.loc[:91]
fr_taylor_rule_exp_pre_gr.to_csv('fr_taylor_exp_pre_gr.csv',index=False)

fr_taylor_rule_exp_post_gr=fr_taylor_rule_exp.loc[91:]
fr_taylor_rule_exp_post_gr.to_csv('fr_taylor_exp_post_gr.csv',index=False)

fr_taylor_rule_exp_post_gr=fr_taylor_rule_exp.loc[91:139]
fr_taylor_rule_exp_post_gr.to_csv('fr_taylor_exp_post_gr.csv',index=False)

fr_output_gap['year']=pd.to_datetime(fr_output_gap['year'],format='%Y')
fr_og_quarters=fr_output_gap.resample('Q',on='year').mean().reset_index()
fr_og_quarters['year']=fr_og_quarters['year'].dt.to_period('Q')
fr_og_quarters.columns=['quarter','output_gap']
fr_og_quarters['output_gap']=fr_og_quarters['output_gap'].ffill()
fr_og_quarters.quarter=fr_og_quarters.quarter.astype(str)

fr_cci_quarters=fr_cci.resample('Q',on='month').mean().reset_index()
fr_cci_quarters['month']=fr_cci_quarters['month'].dt.to_period('Q')
fr_cci_quarters.columns=['quarter','cci']
fr_cci_quarters.quarter=fr_cci_quarters.quarter.astype(str)

fr_inflation_quarters=fr_inflation.resample('Q',on='month').mean().reset_index()
fr_inflation_quarters['month']=fr_inflation_quarters['month'].dt.to_period('Q')
fr_inflation_quarters.columns=['quarter','inflation']
fr_inflation_quarters.quarter=fr_inflation_quarters.quarter.astype(str)

fr_cci_inflation_quarters=fr_inflation_quarters.merge(fr_cci_quarters,on='quarter',how='inner')
fr_cci_inflation_quarters.quarter=pd.to_datetime(fr_cci_inflation_quarters.quarter).dt.to_period('Q')
fr_cci_inflation_quarters.quarter=fr_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

fr_cci_exp_inflation_quarters=eur_exp_infl_quarters.merge(fr_cci_quarters,on='quarter',how='inner')
fr_cci_exp_inflation_quarters.quarter=pd.to_datetime(fr_cci_exp_inflation_quarters.quarter).dt.to_period('Q')
fr_cci_exp_inflation_quarters.quarter=fr_cci_exp_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

fr_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='France']
fr_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
fr_interest_rate_quarters.reset_index(drop=True,inplace=True)
fr_interest_rate_quarters.columns=['quarter','interest_rate']
fr_interest_rate_quarters=fr_interest_rate_quarters.replace('-', '',regex=True)
fr_interest_rate_quarters.quarter=fr_interest_rate_quarters.quarter.astype(str)
fr_interest_rate_quarters['prev_int_rate']=fr_interest_rate_quarters['interest_rate'].shift(1)

fr_taylor_rule_quarters=fr_interest_rate_quarters.merge(fr_inflation_quarters,on='quarter',how='inner')
fr_taylor_rule_quarters['real_interest_rate']=fr_taylor_rule_quarters['interest_rate']-fr_taylor_rule_quarters['inflation']
fr_taylor_rule_quarters['infl_dev']=fr_taylor_rule_quarters['inflation']-2
fr_taylor_rule_quarters=fr_taylor_rule_quarters.merge(fr_og_quarters,on='quarter',how='inner')
fr_taylor_rule_cci_quarters=fr_taylor_rule_quarters.merge(fr_cci_quarters,on='quarter',how='inner')
fr_taylor_rule_cci_quarters.quarter=pd.to_datetime(fr_taylor_rule_cci_quarters.quarter).dt.to_period('Q')
fr_taylor_rule_cci_quarters.quarter=fr_taylor_rule_cci_quarters.quarter.dt.strftime('%Y.%q').astype(float)
fr_taylor_rule_quarters.to_csv('fr_taylor_quarters.csv',index=False)

fr_taylor_rule_quarters_pre_gr=fr_taylor_rule_quarters.loc[:47]
fr_taylor_rule_quarters_pre_gr.to_csv('fr_taylor_quart_pre_gr.csv',index=False)

fr_taylor_rule_quarters_post_gr=fr_taylor_rule_quarters.loc[48:91]
fr_taylor_rule_quarters_post_gr.to_csv('fr_taylor_quart_post_gr.csv',index=False)

fr_taylor_rule_exp_quarters=fr_interest_rate_quarters.merge(eur_exp_infl_quarters,on='quarter',how='inner')
fr_taylor_rule_exp_quarters['exp_infl_dev']=fr_taylor_rule_exp_quarters['exp_inflation']-2
fr_taylor_rule_exp_quarters=fr_taylor_rule_exp_quarters.merge(fr_og_quarters,on='quarter',how='inner')
fr_taylor_rule_exp_quarters.quarter=pd.to_datetime(fr_taylor_rule_exp_quarters.quarter).dt.to_period('Q')
fr_taylor_rule_exp_quarters.quarter=fr_taylor_rule_exp_quarters.quarter.dt.strftime('%Y.%q').astype(float)
fr_taylor_rule_exp_quarters.to_csv('fr_taylor_exp_quarters.csv',index=False)

fr_taylor_rule_exp_quarters_pre_gr=fr_taylor_rule_exp_quarters.loc[:47]
fr_taylor_rule_exp_quarters_pre_gr.to_csv('fr_taylor_exp_quart_pre_gr.csv',index=False)

fr_taylor_rule_exp_quarters_post_gr=fr_taylor_rule_exp_quarters.loc[48:91]
fr_taylor_rule_exp_quarters_post_gr.to_csv('fr_taylor_exp_quart_post_gr.csv',index=False)

plt.close()
sns.histplot(x=fr_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(fr_output_gap)

plt.close()
sns.histplot(x=fr_cci['cci'],bins=20)
plt.show()
summary_stat(fr_cci)

plt.close()
sns.histplot(x=fr_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(fr_cci_quarters)

plt.close()
sns.histplot(x=fr_cci_year['cci'],bins=20)
plt.show()
summary_stat(fr_cci_year)

plt.close()
sns.histplot(x=fr_inflation['inflation'],bins=20)
plt.show()
summary_stat(fr_inflation)

plt.close()
sns.histplot(x=fr_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(fr_inflation_quarters)

plt.close()
sns.histplot(x=fr_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(fr_inflation_year)

plt.close()
sns.lineplot(y=fr_cci_og['output_gap'],x=fr_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=fr_cci_og['cci'],x=fr_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_cci_og.output_gap.corr(fr_cci_og.cci))

plt.close()
sns.lineplot(y=fr_cci_inflation['inflation'],x=fr_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=fr_cci_inflation['cci'],x=fr_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_cci_inflation.inflation.corr(fr_cci_inflation.cci))

plt.close()
sns.lineplot(y=fr_cci_inflation_quarters['inflation'],x=fr_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=fr_cci_inflation_quarters['cci'],x=fr_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_cci_inflation_quarters.inflation.corr(fr_cci_inflation_quarters.cci))

plt.close()
sns.lineplot(y=fr_cci_inflation_year['inflation'],x=fr_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=fr_cci_inflation_year['cci'],x=fr_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_cci_inflation_year.inflation.corr(fr_cci_inflation_year.cci))

plt.close()
sns.lineplot(y=fr_cci_exp_inflation_quarters['exp_inflation'],x=fr_cci_exp_inflation_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=fr_cci_exp_inflation_quarters['cci'],x=fr_cci_exp_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_cci_exp_inflation_quarters.exp_inflation.corr(fr_cci_exp_inflation_quarters.cci))

plt.close()
sns.lineplot(y=fr_cci_exp_inflation['exp_inflation'],x=fr_cci_exp_inflation['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=fr_cci_exp_inflation['cci'],x=fr_cci_exp_inflation['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_cci_exp_inflation.exp_inflation.corr(fr_cci_exp_inflation.cci))

plt.close()
sns.lineplot(y=fr_taylor_rule_cci_quarters['interest_rate'],x=fr_taylor_rule_cci_quarters['quarter'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=fr_taylor_rule_cci_quarters['cci'],x=fr_taylor_rule_cci_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_taylor_rule_cci_quarters['interest_rate'].corr(fr_taylor_rule_cci_quarters['cci']))

plt.close()
sns.lineplot(y=fr_taylor_rule_cci['interest_rate'],x=fr_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=fr_taylor_rule_cci['cci'],x=fr_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',fr_taylor_rule_cci['interest_rate'].corr(fr_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=fr_taylor_rule_cci['interest_rate'],x=fr_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=fr_taylor_rule_cci['output_gap'],x=fr_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.show()
print('corr:',fr_taylor_rule_cci['interest_rate'].corr(fr_taylor_rule_cci['output_gap']))

plt.close()
sns.lineplot(y=fr_taylor_rule_exp_quarters['exp_inflation'],x=fr_taylor_rule_exp_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=fr_taylor_rule_exp_quarters['interest_rate'],x=fr_taylor_rule_exp_quarters['quarter'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',fr_taylor_rule_exp_quarters['exp_inflation'].corr(fr_taylor_rule_exp_quarters['interest_rate']))

plt.close()
sns.lineplot(y=fr_taylor_rule_exp['exp_inflation'],x=fr_taylor_rule_exp['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=fr_taylor_rule_exp['interest_rate'],x=fr_taylor_rule_exp['year'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',fr_taylor_rule_exp['exp_inflation'].corr(fr_taylor_rule_exp['interest_rate']))
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3584169565.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  fr_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3584169565.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  fr_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3584169565.py:19: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  fr_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3584169565.py:26: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  fr_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3584169565.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  fr_interest_rate.drop(columns=['Subject','Country'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3584169565.py:67: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  fr_output_gap['year']=pd.to_datetime(fr_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/3584169565.py:93: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  fr_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Period: 1985 : 2024
Observations: 40
Mean: -0.3626604366804167
Median: -0.5059695810644524
Max: 2.92743628715266
Min: -7.74656038455748
Standard Deviation: 2.0166001281709636
Skewness: -0.9882638266485979
Kurtosis: 3.1436756635944056
Jarque_beraResult(statistic=17.449200670462975, pvalue=0.0001625377402884043)
Period: 1973 : 2023
Observations: 604
Mean: 99.99999956953639
Median: 100.05075
Max: 106.2664
Min: 95.19255
Standard Deviation: 1.762564273193122
Skewness: 0.1685177569704577
Kurtosis: 0.7833963452381076
Jarque_beraResult(statistic=17.650182427034345, pvalue=0.00014699805339013494)
Period: 1973Q1 : 2023Q2
Observations: 202
Mean: 99.99014363036312
Median: 99.99838
Max: 106.11740000000002
Min: 95.44135
Standard Deviation: 1.7590390583221087
Skewness: 0.17728975222327936
Kurtosis: 0.8205460922070134
Jarque_beraResult(statistic=6.04337441187709, pvalue=0.04871895007786897)
Period: 1973 : 2023
Observations: 51
Mean: 99.95815300653597
Median: 100.04343
Max: 105.31543333333333
Min: 95.96296666666666
Standard Deviation: 1.7155191500984164
Skewness: 0.21546599448898127
Kurtosis: 1.0122242079741457
Jarque_beraResult(statistic=1.7325422055023767, pvalue=0.4205166928432704)
Period: 1997 : 2023
Observations: 317
Mean: 1.7176656151419554
Median: 1.6
Max: 7.3
Min: -0.8
Standard Deviation: 1.387809804112181
Skewness: 1.8485737410068757
Kurtosis: 4.888703868783274
Jarque_beraResult(statistic=482.27807985555035, pvalue=0.0)
Period: 1997Q1 : 2023Q2
Observations: 106
Mean: 1.7325471698113208
Median: 1.5333333333333332
Max: 7.0
Min: -0.46666666666666673
Standard Deviation: 1.3984049531869278
Skewness: 1.8965615555813624
Kurtosis: 4.998597986202583
Jarque_beraResult(statistic=159.72613411608444, pvalue=0.0)
Period: 1996 : 2022
Observations: 27
Mean: 1.6555555555555557
Median: 1.8
Max: 5.9
Min: 0.1
Standard Deviation: 1.1550335770455178
Skewness: 1.780954688109498
Kurtosis: 6.186261696697772
Jarque_beraResult(statistic=39.545763244277, pvalue=2.586703296003634e-09)
corr: 0.434506314497801
corr: -0.3219216896498525
corr: -0.3442536434343438
corr: -0.27258186943194657
corr: -0.25806007178827733
corr: -0.4169409243573116
corr: 0.3890377719517636
corr: 0.40822933103036446
corr: 0.48883180694379375
corr: 0.5823922831611823
corr: 0.44884012539410645
In [419]:
fr_taylor_rule_quarters.loc[47:91]
Out[419]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
47 2008Q4 4.214667 4.981800 2.033333 2.181334 0.033333 1.577778
48 2009Q1 2.011700 4.214667 0.733333 1.278367 -1.266667 -2.350277
49 2009Q2 1.310633 2.011700 -0.266667 1.577300 -2.266667 -2.350277
50 2009Q3 0.869200 1.310633 -0.466667 1.335867 -2.466667 -2.350277
51 2009Q4 0.721900 0.869200 0.433333 0.288567 -1.566667 -2.350277
52 2010Q1 0.662133 0.721900 1.433333 -0.771200 -0.566667 -1.478637
53 2010Q2 0.686267 0.662133 1.833333 -1.147067 -0.166667 -1.478637
54 2010Q3 0.874933 0.686267 1.766667 -0.891733 -0.233333 -1.478637
55 2010Q4 1.020467 0.874933 1.866667 -0.846200 -0.133333 -1.478637
56 2011Q1 1.093133 1.020467 2.000000 -0.906867 0.000000 -0.179850
57 2011Q2 1.411633 1.093133 2.233333 -0.821700 0.233333 -0.179850
58 2011Q3 1.562067 1.411633 2.300000 -0.737933 0.300000 -0.179850
59 2011Q4 1.495567 1.562067 2.633333 -1.137766 0.633333 -0.179850
60 2012Q1 1.043000 1.495567 2.566667 -1.523667 0.566667 -0.688945
61 2012Q2 0.696033 1.043000 2.333333 -1.637300 0.333333 -0.688945
62 2012Q3 0.358567 0.696033 2.266667 -1.908100 0.266667 -0.688945
63 2012Q4 0.195133 0.358567 1.733333 -1.538200 -0.266667 -0.688945
64 2013Q1 0.211467 0.195133 1.233333 -1.021867 -0.766667 -0.877772
65 2013Q2 0.206800 0.211467 0.900000 -0.693200 -1.100000 -0.877772
66 2013Q3 0.223500 0.206800 1.066667 -0.843167 -0.933333 -0.877772
67 2013Q4 0.240900 0.223500 0.766667 -0.525767 -1.233333 -0.877772
68 2014Q1 0.295133 0.240900 0.900000 -0.604867 -1.100000 -0.823634
69 2014Q2 0.298567 0.295133 0.733333 -0.434767 -1.266667 -0.823634
70 2014Q3 0.164567 0.298567 0.500000 -0.335433 -1.500000 -0.823634
71 2014Q4 0.081467 0.164567 0.333333 -0.251867 -1.666667 -0.823634
72 2015Q1 0.046033 0.081467 -0.233333 0.279367 -2.233333 -0.731416
73 2015Q2 -0.006533 0.046033 0.233333 -0.239867 -1.766667 -0.731416
74 2015Q3 -0.027800 -0.006533 0.133333 -0.161133 -1.866667 -0.731416
75 2015Q4 -0.089167 -0.027800 0.200000 -0.289167 -1.800000 -0.731416
76 2016Q1 -0.186067 -0.089167 0.033333 -0.219400 -1.966667 -0.820504
77 2016Q2 -0.258100 -0.186067 0.100000 -0.358100 -1.900000 -0.820504
78 2016Q3 -0.298100 -0.258100 0.433333 -0.731433 -1.566667 -0.820504
79 2016Q4 -0.312500 -0.298100 0.666667 -0.979167 -1.333333 -0.820504
80 2017Q1 -0.327800 -0.312500 1.466667 -1.794467 -0.533333 0.389316
81 2017Q2 -0.329967 -0.327800 1.033333 -1.363300 -0.966667 0.389316
82 2017Q3 -0.329633 -0.329967 0.966667 -1.296300 -1.033333 0.389316
83 2017Q4 -0.328800 -0.329633 1.200000 -1.528800 -0.800000 0.389316
84 2018Q1 -0.328300 -0.328800 1.500000 -1.828300 -0.500000 0.959732
85 2018Q2 -0.325233 -0.328300 2.133333 -2.458567 0.133333 0.959732
86 2018Q3 -0.319500 -0.325233 2.566667 -2.886167 0.566667 0.959732
87 2018Q4 -0.315333 -0.319500 2.200000 -2.515333 0.200000 0.959732
88 2019Q1 -0.308533 -0.315333 1.433333 -1.741867 -0.566667 1.541862
89 2019Q2 -0.317100 -0.308533 1.333333 -1.650433 -0.666667 1.541862
90 2019Q3 -0.396733 -0.317100 1.233333 -1.630067 -0.766667 1.541862
91 2019Q4 -0.402967 -0.396733 1.233333 -1.636300 -0.766667 1.541862

Italy¶

In [425]:
ita_output_gap=oecd_output_gap[oecd_output_gap['Country']=='Italy']
ita_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
ita_output_gap.reset_index(drop=True,inplace=True)
ita_output_gap.columns=['year','output_gap']

ita_cci=oecd_cci[oecd_cci['Country']=='Italy']
ita_cci.drop(columns=['Country','Subject'],inplace=True)
ita_cci.reset_index(drop=True,inplace=True)
ita_cci.columns=['month','cci']

ita_cci_year=ita_cci.resample('Y',on='month').mean().reset_index()
ita_cci_year['year'] = ita_cci_year['month'].dt.year
ita_cci_year.drop(columns='month',inplace=True)
ita_cci_year=ita_cci_year[['year', 'cci']]

ita_cci_og=ita_output_gap.merge(ita_cci_year,on='year',how='inner')

ita_inflation=oecd_hicp[oecd_hicp['Country']=='Italy']
ita_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
ita_inflation.reset_index(drop=True,inplace=True)
ita_inflation.columns=['month','inflation']

ita_cci_inflation=ita_inflation.merge(ita_cci,on='month',how='inner')

ita_inflation_year=oecd_hicp_year[oecd_hicp_year['Country']=='Italy']
ita_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
ita_inflation_year.reset_index(drop=True,inplace=True)
ita_inflation_year.columns=['year','inflation']

ita_cci_inflation_year=ita_inflation_year.merge(ita_cci_year,on='year',how='inner')

ita_cci_exp_inflation=eur_exp_infl.merge(ita_cci_year,on='year',how='inner')

ita_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='Italy']

ita_interest_rate.drop(columns=['Subject','Country'],inplace=True)
ita_interest_rate.reset_index(drop=True,inplace=True)
ita_interest_rate.columns=['year','interest_rate']

ita_taylor_rule=ita_interest_rate.merge(ita_inflation_year,on='year',how='inner')
ita_taylor_rule['real_interest_rate']=ita_taylor_rule['interest_rate']-ita_taylor_rule['inflation']
ita_taylor_rule['infl_dev']=ita_inflation_year['inflation']-2
ita_taylor_rule=ita_taylor_rule.merge(ita_output_gap,on='year',how='inner')
ita_taylor_rule_cci=ita_taylor_rule.merge(ita_cci_year,on='year',how='inner')
ita_taylor_rule_cci=ita_taylor_rule_cci[ita_taylor_rule_cci['year']<2023]
ita_taylor_rule.to_csv('ita_taylor.csv',index=False)
ita_taylor_rule_pre_gr=ita_taylor_rule[ita_taylor_rule['year']<2008]
ita_taylor_rule_pre_gr.to_csv('ita_taylor_pre_gr.csv',index=False)

ita_taylor_rule_post_gr=ita_taylor_rule[(ita_taylor_rule['year']<2020)&(ita_taylor_rule['year']>2007)]
ita_taylor_rule_post_gr.to_csv('ita_taylor_post_gr.csv',index=False)

ita_taylor_rule_exp=ita_interest_rate.merge(eur_exp_infl,on='year',how='inner')
ita_taylor_rule_exp['exp_infl_dev']=ita_taylor_rule_exp['exp_inflation']-2
ita_taylor_rule_exp=ita_taylor_rule_exp.merge(ita_output_gap,on='year',how='inner')
ita_taylor_rule_exp.to_csv('ita_taylor_exp.csv',index=False)

ita_taylor_rule_exp_pre_gr=ita_taylor_rule_exp.loc[:91]
ita_taylor_rule_exp_pre_gr.to_csv('ita_taylor_exp_pre_gr.csv',index=False)

ita_taylor_rule_exp_post_gr=ita_taylor_rule_exp.loc[91:]
ita_taylor_rule_exp_post_gr.to_csv('ita_taylor_exp_post_gr.csv',index=False)

ita_taylor_rule_exp_post_gr=ita_taylor_rule_exp.loc[91:139]
ita_taylor_rule_exp_post_gr.to_csv('ita_taylor_exp_post_gr.csv',index=False)

ita_output_gap['year']=pd.to_datetime(ita_output_gap['year'],format='%Y')
ita_og_quarters=ita_output_gap.resample('Q',on='year').mean().reset_index()
ita_og_quarters['year']=ita_og_quarters['year'].dt.to_period('Q')
ita_og_quarters.columns=['quarter','output_gap']
ita_og_quarters['output_gap']=ita_og_quarters['output_gap'].ffill()
ita_og_quarters.quarter=ita_og_quarters.quarter.astype(str)

ita_cci_quarters=ita_cci.resample('Q',on='month').mean().reset_index()
ita_cci_quarters['month']=ita_cci_quarters['month'].dt.to_period('Q')
ita_cci_quarters.columns=['quarter','cci']
ita_cci_quarters.quarter=ita_cci_quarters.quarter.astype(str)

ita_inflation_quarters=ita_inflation.resample('Q',on='month').mean().reset_index()
ita_inflation_quarters['month']=ita_inflation_quarters['month'].dt.to_period('Q')
ita_inflation_quarters.columns=['quarter','inflation']
ita_inflation_quarters.quarter=ita_inflation_quarters.quarter.astype(str)

ita_cci_inflation_quarters=ita_inflation_quarters.merge(ita_cci_quarters,on='quarter',how='inner')
ita_cci_inflation_quarters.quarter=pd.to_datetime(ita_cci_inflation_quarters.quarter).dt.to_period('Q')
ita_cci_inflation_quarters.quarter=ita_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

ita_cci_exp_inflation_quarters=eur_exp_infl_quarters.merge(ita_cci_quarters,on='quarter',how='inner')
ita_cci_exp_inflation_quarters.quarter=pd.to_datetime(ita_cci_exp_inflation_quarters.quarter).dt.to_period('Q')
ita_cci_exp_inflation_quarters.quarter=ita_cci_exp_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

ita_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='Italy']
ita_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
ita_interest_rate_quarters.reset_index(drop=True,inplace=True)
ita_interest_rate_quarters.columns=['quarter','interest_rate']
ita_interest_rate_quarters=ita_interest_rate_quarters.replace('-', '',regex=True)
ita_interest_rate_quarters.quarter=ita_interest_rate_quarters.quarter.astype(str)
ita_interest_rate_quarters['prev_int_rate']=ita_interest_rate_quarters['interest_rate'].shift(1)

ita_taylor_rule_quarters=ita_interest_rate_quarters.merge(ita_inflation_quarters,on='quarter',how='inner')
ita_taylor_rule_quarters['real_interest_rate']=ita_taylor_rule_quarters['interest_rate']-ita_taylor_rule_quarters['inflation']
ita_taylor_rule_quarters['infl_dev']=ita_taylor_rule_quarters['inflation']-2
ita_taylor_rule_quarters=ita_taylor_rule_quarters.merge(ita_og_quarters,on='quarter',how='inner')
ita_taylor_rule_cci_quarters=ita_taylor_rule_quarters.merge(ita_cci_quarters,on='quarter',how='inner')
ita_taylor_rule_cci_quarters.quarter=pd.to_datetime(ita_taylor_rule_cci_quarters.quarter).dt.to_period('Q')
ita_taylor_rule_cci_quarters.quarter=ita_taylor_rule_cci_quarters.quarter.dt.strftime('%Y.%q').astype(float)
ita_taylor_rule_quarters.to_csv('ita_taylor_quarters.csv',index=False)

ita_taylor_rule_quarters_pre_gr=ita_taylor_rule_quarters.loc[:47]
ita_taylor_rule_quarters_pre_gr.to_csv('ita_taylor_quart_pre_gr.csv',index=False)

ita_taylor_rule_quarters_post_gr=ita_taylor_rule_quarters.loc[47:91]
ita_taylor_rule_quarters_post_gr.to_csv('ita_taylor_quart_post_gr.csv',index=False)

ita_taylor_rule_exp_quarters=ita_interest_rate_quarters.merge(eur_exp_infl_quarters,on='quarter',how='inner')
ita_taylor_rule_exp_quarters['exp_infl_dev']=ita_taylor_rule_exp_quarters['exp_inflation']-2
ita_taylor_rule_exp_quarters=ita_taylor_rule_exp_quarters.merge(ita_og_quarters,on='quarter',how='inner')
ita_taylor_rule_exp_quarters.quarter=pd.to_datetime(ita_taylor_rule_exp_quarters.quarter).dt.to_period('Q')
ita_taylor_rule_exp_quarters.quarter=ita_taylor_rule_exp_quarters.quarter.dt.strftime('%Y.%q').astype(float)
ita_taylor_rule_exp_quarters.to_csv('ita_taylor_exp_quarters.csv',index=False)

ita_taylor_rule_exp_quarters_pre_gr=ita_taylor_rule_exp_quarters.loc[:47]
ita_taylor_rule_exp_quarters_pre_gr.to_csv('ita_taylor_exp_quart_pre_gr.csv',index=False)

ita_taylor_rule_exp_quarters_post_gr=ita_taylor_rule_exp_quarters.loc[48:91]
ita_taylor_rule_exp_quarters_post_gr.to_csv('ita_taylor_exp_quart_post_gr.csv',index=False)

plt.close()
sns.histplot(x=ita_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(ita_output_gap)

plt.close()
sns.histplot(x=ita_cci['cci'],bins=20)
plt.show()
summary_stat(ita_cci)

plt.close()
sns.histplot(x=ita_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(ita_cci_quarters)

plt.close()
sns.histplot(x=ita_cci_year['cci'],bins=20)
plt.show()
summary_stat(ita_cci_year)

plt.close()
sns.histplot(x=ita_inflation['inflation'],bins=20)
plt.show()
summary_stat(ita_inflation)

plt.close()
sns.histplot(x=ita_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(ita_inflation_quarters)

plt.close()
sns.histplot(x=ita_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(ita_inflation_year)

plt.close()
sns.lineplot(y=ita_cci_og['output_gap'],x=ita_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=ita_cci_og['cci'],x=ita_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ita_cci_og.output_gap.corr(ita_cci_og.cci))

plt.close()
sns.lineplot(y=ita_cci_inflation['inflation'],x=ita_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=ita_cci_inflation['cci'],x=ita_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ita_cci_inflation.inflation.corr(ita_cci_inflation.cci))

plt.close()
sns.lineplot(y=ita_cci_inflation_quarters['inflation'],x=ita_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=ita_cci_inflation_quarters['cci'],x=ita_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend(loc='upper right')
plt.show()
print('corr:',ita_cci_inflation_quarters.inflation.corr(ita_cci_inflation_quarters.cci))

plt.close()
sns.lineplot(y=ita_cci_inflation_year['inflation'],x=ita_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=ita_cci_inflation_year['cci'],x=ita_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend(loc='upper right')
plt.show()
print('corr:',ita_cci_inflation_year.inflation.corr(ita_cci_inflation_year.cci))

plt.close()
sns.lineplot(y=ita_cci_exp_inflation_quarters['exp_inflation'],x=ita_cci_exp_inflation_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ita_cci_exp_inflation_quarters['cci'],x=ita_cci_exp_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend(loc='upper right')
plt.show()
print('corr:',ita_cci_exp_inflation_quarters.exp_inflation.corr(ita_cci_exp_inflation_quarters.cci))

plt.close()
sns.lineplot(y=ita_cci_exp_inflation['exp_inflation'],x=ita_cci_exp_inflation['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ita_cci_exp_inflation['cci'],x=ita_cci_exp_inflation['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ita_cci_exp_inflation.exp_inflation.corr(ita_cci_exp_inflation.cci))

plt.close()
sns.lineplot(y=ita_taylor_rule_cci_quarters['interest_rate'],x=ita_taylor_rule_cci_quarters['quarter'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=ita_taylor_rule_cci_quarters['cci'],x=ita_taylor_rule_cci_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend(loc='upper right')
plt.show()
print('corr:',ita_taylor_rule_cci_quarters['interest_rate'].corr(ita_taylor_rule_cci_quarters['cci']))

plt.close()
sns.lineplot(y=ita_taylor_rule_cci['interest_rate'],x=ita_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=ita_taylor_rule_cci['cci'],x=ita_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',ita_taylor_rule_cci['interest_rate'].corr(ita_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=ita_taylor_rule_cci['interest_rate'],x=ita_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=ita_taylor_rule_cci['output_gap'],x=ita_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.show()
print('corr:',ita_taylor_rule_cci['interest_rate'].corr(ita_taylor_rule_cci['output_gap']))

plt.close()
sns.lineplot(y=ita_taylor_rule_exp_quarters['exp_inflation'],x=ita_taylor_rule_exp_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ita_taylor_rule_exp_quarters['interest_rate'],x=ita_taylor_rule_exp_quarters['quarter'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',ita_taylor_rule_exp_quarters['exp_inflation'].corr(ita_taylor_rule_exp_quarters['interest_rate']))

plt.close()
sns.lineplot(y=ita_taylor_rule_exp['exp_inflation'],x=ita_taylor_rule_exp['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=ita_taylor_rule_exp['interest_rate'],x=ita_taylor_rule_exp['year'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',ita_taylor_rule_exp['exp_inflation'].corr(ita_taylor_rule_exp['interest_rate']))
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/594115895.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ita_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/594115895.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ita_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/594115895.py:19: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ita_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/594115895.py:26: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ita_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/594115895.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ita_interest_rate.drop(columns=['Subject','Country'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/594115895.py:67: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ita_output_gap['year']=pd.to_datetime(ita_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/594115895.py:93: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  ita_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Period: 1985 : 2024
Observations: 40
Mean: -0.7052387933469797
Median: -0.4893354860992015
Max: 3.69917837114431
Min: -8.39211734611194
Standard Deviation: 2.4384177333998127
Skewness: -0.7179603561760093
Kurtosis: 1.0143355247377435
Jarque_beraResult(statistic=4.1073575733073815, pvalue=0.12826218539044532)
Period: 1973 : 2023
Observations: 604
Mean: 100.00000057947027
Median: 100.37165
Max: 103.5685
Min: 93.68179
Standard Deviation: 2.0183429016289685
Skewness: -0.644337496216801
Kurtosis: -0.15658978059125017
Jarque_beraResult(statistic=42.273330581040504, pvalue=6.613980474412529e-10)
Period: 1973Q1 : 2023Q2
Observations: 202
Mean: 100.00001608910893
Median: 100.33849999999998
Max: 103.36053333333332
Min: 93.81393333333334
Standard Deviation: 2.0062975342667135
Skewness: -0.6527188521772554
Kurtosis: -0.12996096423740422
Jarque_beraResult(statistic=14.336419963600083, pvalue=0.0007707010661719416)
Period: 1973 : 2023
Observations: 51
Mean: 99.9966137745098
Median: 100.30048666666666
Max: 102.909675
Min: 95.56572833333333
Standard Deviation: 1.925387417944809
Skewness: -0.6614621164409756
Kurtosis: -0.1727167383998096
Jarque_beraResult(statistic=3.658500408487683, pvalue=0.16053389029053944)
Period: 1997 : 2023
Observations: 317
Mean: 2.113249211356467
Median: 2.0
Max: 12.6
Min: -1.0
Standard Deviation: 1.9892148706515371
Skewness: 2.558954428253487
Kurtosis: 9.35009523901467
Jarque_beraResult(statistic=1456.8601524813519, pvalue=0.0)
Period: 1997Q1 : 2023Q2
Observations: 106
Mean: 2.133018867924528
Median: 2.0166666666666666
Max: 12.5
Min: -0.39999999999999997
Standard Deviation: 2.0063575951561106
Skewness: 2.5506725715887915
Kurtosis: 9.17770500607631
Jarque_beraResult(statistic=445.56269227344853, pvalue=0.0)
Period: 1996 : 2022
Observations: 27
Mean: 2.0555555555555554
Median: 1.9
Max: 8.7
Min: -0.1
Standard Deviation: 1.7138201443498926
Skewness: 2.196350746127785
Kurtosis: 8.131565520861336
Jarque_beraResult(statistic=66.67615072492514, pvalue=3.3306690738754696e-15)
corr: 0.37831535453832926
corr: -0.1909330537882259
corr: -0.18711563873730536
corr: -0.1597905315202495
corr: -0.12686442680815718
corr: -0.18178981687116888
corr: 0.3983319827969095
corr: 0.4380241403719528
corr: 0.29949130801623897
corr: 0.5823922831611823
corr: 0.44884012539410645
In [424]:
ita_taylor_rule_quarters.loc[47:94]
Out[424]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
47 2008Q4 4.214667 4.981800 2.933333 1.281334 0.933333 2.316160
48 2009Q1 2.011700 4.214667 1.366667 0.645033 -0.633333 -3.246192
49 2009Q2 1.310633 2.011700 0.833333 0.477300 -1.166667 -3.246192
50 2009Q3 0.869200 1.310633 0.100000 0.769200 -1.900000 -3.246192
51 2009Q4 0.721900 0.869200 0.766667 -0.044767 -1.233333 -3.246192
52 2010Q1 0.662133 0.721900 1.233333 -0.571200 -0.766667 -1.539922
53 2010Q2 0.686267 0.662133 1.566667 -0.880400 -0.433333 -1.539922
54 2010Q3 0.874933 0.686267 1.700000 -0.825067 -0.300000 -1.539922
55 2010Q4 1.020467 0.874933 1.966667 -0.946200 -0.033333 -1.539922
56 2011Q1 1.093133 1.020467 2.333333 -1.240200 0.333333 -0.506604
57 2011Q2 1.411633 1.093133 2.966667 -1.555034 0.966667 -0.506604
58 2011Q3 1.562067 1.411633 2.700000 -1.137933 0.700000 -0.506604
59 2011Q4 1.495567 1.562067 3.700000 -2.204433 1.700000 -0.506604
60 2012Q1 1.043000 1.495567 3.566667 -2.523667 1.566667 -3.174988
61 2012Q2 0.696033 1.043000 3.666667 -2.970633 1.666667 -3.174988
62 2012Q3 0.358567 0.696033 3.466667 -3.108100 1.466667 -3.174988
63 2012Q4 0.195133 0.358567 2.666667 -2.471533 0.666667 -3.174988
64 2013Q1 0.211467 0.195133 2.066667 -1.855200 0.066667 -4.495913
65 2013Q2 0.206800 0.211467 1.200000 -0.993200 -0.800000 -4.495913
66 2013Q3 0.223500 0.206800 1.066667 -0.843167 -0.933333 -4.495913
67 2013Q4 0.240900 0.223500 0.633333 -0.392433 -1.366667 -4.495913
68 2014Q1 0.295133 0.240900 0.433333 -0.138200 -1.566667 -3.920239
69 2014Q2 0.298567 0.295133 0.400000 -0.101433 -1.600000 -3.920239
70 2014Q3 0.164567 0.298567 -0.066667 0.231233 -2.066667 -3.920239
71 2014Q4 0.081467 0.164567 0.166667 -0.085200 -1.833333 -3.920239
72 2015Q1 0.046033 0.081467 -0.133333 0.179367 -2.133333 -2.908960
73 2015Q2 -0.006533 0.046033 0.100000 -0.106533 -1.900000 -2.908960
74 2015Q3 -0.027800 -0.006533 0.300000 -0.327800 -1.700000 -2.908960
75 2015Q4 -0.089167 -0.027800 0.166667 -0.255833 -1.833333 -2.908960
76 2016Q1 -0.186067 -0.089167 0.000000 -0.186067 -2.000000 -1.357736
77 2016Q2 -0.258100 -0.186067 -0.300000 0.041900 -2.300000 -1.357736
78 2016Q3 -0.298100 -0.258100 -0.066667 -0.231433 -2.066667 -1.357736
79 2016Q4 -0.312500 -0.298100 0.166667 -0.479167 -1.833333 -1.357736
80 2017Q1 -0.327800 -0.312500 1.333333 -1.661133 -0.666667 0.301301
81 2017Q2 -0.329967 -0.327800 1.600000 -1.929967 -0.400000 0.301301
82 2017Q3 -0.329633 -0.329967 1.300000 -1.629633 -0.700000 0.301301
83 2017Q4 -0.328800 -0.329633 1.066667 -1.395467 -0.933333 0.301301
84 2018Q1 -0.328300 -0.328800 0.866667 -1.194967 -1.133333 0.851707
85 2018Q2 -0.325233 -0.328300 1.000000 -1.325233 -1.000000 0.851707
86 2018Q3 -0.319500 -0.325233 1.666667 -1.986167 -0.333333 0.851707
87 2018Q4 -0.315333 -0.319500 1.500000 -1.815333 -0.500000 0.851707
88 2019Q1 -0.308533 -0.315333 1.033333 -1.341867 -0.966667 1.014667
89 2019Q2 -0.317100 -0.308533 0.933333 -1.250433 -1.066667 1.014667
90 2019Q3 -0.396733 -0.317100 0.333333 -0.730067 -1.666667 1.014667
91 2019Q4 -0.402967 -0.396733 0.300000 -0.702967 -1.700000 1.014667
92 2020Q1 -0.405500 -0.402967 0.233333 -0.638833 -1.766667 -8.392117
93 2020Q2 -0.300667 -0.405500 -0.200000 -0.100667 -2.200000 -8.392117
94 2020Q3 -0.471733 -0.300667 -0.233333 -0.238400 -2.233333 -8.392117

Greece¶

In [427]:
gre_output_gap=oecd_output_gap[oecd_output_gap['Country']=='Greece']
gre_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
gre_output_gap.reset_index(drop=True,inplace=True)
gre_output_gap.columns=['year','output_gap']

gre_cci=oecd_cci[oecd_cci['Country']=='Greece']
gre_cci.drop(columns=['Country','Subject'],inplace=True)
gre_cci.reset_index(drop=True,inplace=True)
gre_cci.columns=['month','cci']

gre_cci_year=gre_cci.resample('Y',on='month').mean().reset_index()
gre_cci_year['year'] = gre_cci_year['month'].dt.year
gre_cci_year.drop(columns='month',inplace=True)
gre_cci_year=gre_cci_year[['year', 'cci']]

gre_cci_og=gre_output_gap.merge(gre_cci_year,on='year',how='inner')

gre_inflation=oecd_hicp[oecd_hicp['Country']=='Greece']
gre_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
gre_inflation.reset_index(drop=True,inplace=True)
gre_inflation.columns=['month','inflation']

gre_cci_inflation=gre_inflation.merge(gre_cci,on='month',how='inner')

gre_inflation_year=oecd_hicp_year[oecd_hicp_year['Country']=='Greece']
gre_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
gre_inflation_year.reset_index(drop=True,inplace=True)
gre_inflation_year.columns=['year','inflation']

gre_cci_inflation_year=gre_inflation_year.merge(gre_cci_year,on='year',how='inner')

gre_cci_exp_inflation=eur_exp_infl.merge(gre_cci_year,on='year',how='inner')

gre_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='Greece']

gre_interest_rate.drop(columns=['Subject','Country'],inplace=True)
gre_interest_rate.reset_index(drop=True,inplace=True)
gre_interest_rate.columns=['year','interest_rate']

gre_taylor_rule=gre_interest_rate.merge(gre_inflation_year,on='year',how='inner')
gre_taylor_rule['real_interest_rate']=gre_taylor_rule['interest_rate']-gre_taylor_rule['inflation']
gre_taylor_rule['infl_dev']=gre_inflation_year['inflation']-2
gre_taylor_rule=gre_taylor_rule.merge(gre_output_gap,on='year',how='inner')
gre_taylor_rule_cci=gre_taylor_rule.merge(gre_cci_year,on='year',how='inner')
gre_taylor_rule_cci=gre_taylor_rule_cci[gre_taylor_rule_cci['year']<2023]
gre_taylor_rule.to_csv('gre_taylor.csv',index=False)
gre_taylor_rule_pre_gr=gre_taylor_rule[gre_taylor_rule['year']<2008]
gre_taylor_rule_pre_gr.to_csv('gre_taylor_pre_gr.csv',index=False)

gre_taylor_rule_post_gr=gre_taylor_rule[(gre_taylor_rule['year']<2020)&(gre_taylor_rule['year']>2007)]
gre_taylor_rule_post_gr.to_csv('gre_taylor_post_gr.csv',index=False)

gre_taylor_rule_exp=gre_interest_rate.merge(eur_exp_infl,on='year',how='inner')
gre_taylor_rule_exp['exp_infl_dev']=gre_taylor_rule_exp['exp_inflation']-2
gre_taylor_rule_exp=gre_taylor_rule_exp.merge(gre_output_gap,on='year',how='inner')
gre_taylor_rule_exp.to_csv('gre_taylor_exp.csv',index=False)

gre_taylor_rule_exp_pre_gr=gre_taylor_rule_exp.loc[:91]
gre_taylor_rule_exp_pre_gr.to_csv('gre_taylor_exp_pre_gr.csv',index=False)

gre_taylor_rule_exp_post_gr=gre_taylor_rule_exp.loc[91:]
gre_taylor_rule_exp_post_gr.to_csv('gre_taylor_exp_post_gr.csv',index=False)

gre_taylor_rule_exp_post_gr=gre_taylor_rule_exp.loc[91:139]
gre_taylor_rule_exp_post_gr.to_csv('gre_taylor_exp_post_gr.csv',index=False)

gre_output_gap['year']=pd.to_datetime(gre_output_gap['year'],format='%Y')
gre_og_quarters=gre_output_gap.resample('Q',on='year').mean().reset_index()
gre_og_quarters['year']=gre_og_quarters['year'].dt.to_period('Q')
gre_og_quarters.columns=['quarter','output_gap']
gre_og_quarters['output_gap']=gre_og_quarters['output_gap'].ffill()
gre_og_quarters.quarter=gre_og_quarters.quarter.astype(str)

gre_cci_quarters=gre_cci.resample('Q',on='month').mean().reset_index()
gre_cci_quarters['month']=gre_cci_quarters['month'].dt.to_period('Q')
gre_cci_quarters.columns=['quarter','cci']
gre_cci_quarters.quarter=gre_cci_quarters.quarter.astype(str)

gre_inflation_quarters=gre_inflation.resample('Q',on='month').mean().reset_index()
gre_inflation_quarters['month']=gre_inflation_quarters['month'].dt.to_period('Q')
gre_inflation_quarters.columns=['quarter','inflation']
gre_inflation_quarters.quarter=gre_inflation_quarters.quarter.astype(str)

gre_cci_inflation_quarters=gre_inflation_quarters.merge(gre_cci_quarters,on='quarter',how='inner')
gre_cci_inflation_quarters.quarter=pd.to_datetime(gre_cci_inflation_quarters.quarter).dt.to_period('Q')
gre_cci_inflation_quarters.quarter=gre_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

gre_cci_exp_inflation_quarters=eur_exp_infl_quarters.merge(gre_cci_quarters,on='quarter',how='inner')
gre_cci_exp_inflation_quarters.quarter=pd.to_datetime(gre_cci_exp_inflation_quarters.quarter).dt.to_period('Q')
gre_cci_exp_inflation_quarters.quarter=gre_cci_exp_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

gre_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='Greece']
gre_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
gre_interest_rate_quarters.reset_index(drop=True,inplace=True)
gre_interest_rate_quarters.columns=['quarter','interest_rate']
gre_interest_rate_quarters=gre_interest_rate_quarters.replace('-', '',regex=True)
gre_interest_rate_quarters.quarter=gre_interest_rate_quarters.quarter.astype(str)
gre_interest_rate_quarters['prev_int_rate']=gre_interest_rate_quarters['interest_rate'].shift(1)

gre_taylor_rule_quarters=gre_interest_rate_quarters.merge(gre_inflation_quarters,on='quarter',how='inner')
gre_taylor_rule_quarters['real_interest_rate']=gre_taylor_rule_quarters['interest_rate']-gre_taylor_rule_quarters['inflation']
gre_taylor_rule_quarters['infl_dev']=gre_taylor_rule_quarters['inflation']-2
gre_taylor_rule_quarters=gre_taylor_rule_quarters.merge(gre_og_quarters,on='quarter',how='inner')
gre_taylor_rule_cci_quarters=gre_taylor_rule_quarters.merge(gre_cci_quarters,on='quarter',how='inner')
gre_taylor_rule_cci_quarters.quarter=pd.to_datetime(gre_taylor_rule_cci_quarters.quarter).dt.to_period('Q')
gre_taylor_rule_cci_quarters.quarter=gre_taylor_rule_cci_quarters.quarter.dt.strftime('%Y.%q').astype(float)
gre_taylor_rule_quarters.to_csv('gre_taylor_quarters.csv',index=False)

gre_taylor_rule_quarters_pre_gr=gre_taylor_rule_quarters.loc[:47]
gre_taylor_rule_quarters_pre_gr.to_csv('gre_taylor_quart_pre_gr.csv',index=False)

gre_taylor_rule_quarters_post_gr=gre_taylor_rule_quarters.loc[48:91]
gre_taylor_rule_quarters_post_gr.to_csv('gre_taylor_quart_post_gr.csv',index=False)

gre_taylor_rule_exp_quarters=gre_interest_rate_quarters.merge(eur_exp_infl_quarters,on='quarter',how='inner')
gre_taylor_rule_exp_quarters['exp_infl_dev']=gre_taylor_rule_exp_quarters['exp_inflation']-2
gre_taylor_rule_exp_quarters=gre_taylor_rule_exp_quarters.merge(gre_og_quarters,on='quarter',how='inner')
gre_taylor_rule_exp_quarters.quarter=pd.to_datetime(gre_taylor_rule_exp_quarters.quarter).dt.to_period('Q')
gre_taylor_rule_exp_quarters.quarter=gre_taylor_rule_exp_quarters.quarter.dt.strftime('%Y.%q').astype(float)
gre_taylor_rule_exp_quarters.to_csv('gre_taylor_exp_quarters.csv',index=False)

gre_taylor_rule_exp_quarters_pre_gr=gre_taylor_rule_exp_quarters.loc[:47]
gre_taylor_rule_exp_quarters_pre_gr.to_csv('gre_taylor_exp_quart_pre_gr.csv',index=False)

gre_taylor_rule_exp_quarters_post_gr=gre_taylor_rule_exp_quarters.loc[48:91]
gre_taylor_rule_exp_quarters_post_gr.to_csv('gre_taylor_exp_quart_post_gr.csv',index=False)

plt.close()
sns.histplot(x=gre_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(gre_output_gap)

plt.close()
sns.histplot(x=gre_cci['cci'],bins=20)
plt.show()
summary_stat(gre_cci)

plt.close()
sns.histplot(x=gre_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(gre_cci_quarters)

plt.close()
sns.histplot(x=gre_cci_year['cci'],bins=20)
plt.show()
summary_stat(gre_cci_year)

plt.close()
sns.histplot(x=gre_inflation['inflation'],bins=20)
plt.show()
summary_stat(gre_inflation)

plt.close()
sns.histplot(x=gre_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(gre_inflation_quarters)

plt.close()
sns.histplot(x=gre_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(gre_inflation_year)

plt.close()
sns.lineplot(y=gre_cci_og['output_gap'],x=gre_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=gre_cci_og['cci'],x=gre_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_cci_og.output_gap.corr(gre_cci_og.cci))

plt.close()
sns.lineplot(y=gre_cci_inflation['inflation'],x=gre_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=gre_cci_inflation['cci'],x=gre_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_cci_inflation.inflation.corr(gre_cci_inflation.cci))

plt.close()
sns.lineplot(y=gre_cci_inflation_quarters['inflation'],x=gre_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=gre_cci_inflation_quarters['cci'],x=gre_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_cci_inflation_quarters.inflation.corr(gre_cci_inflation_quarters.cci))

plt.close()
sns.lineplot(y=gre_cci_inflation_year['inflation'],x=gre_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=gre_cci_inflation_year['cci'],x=gre_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_cci_inflation_year.inflation.corr(gre_cci_inflation_year.cci))

plt.close()
sns.lineplot(y=gre_cci_exp_inflation_quarters['exp_inflation'],x=gre_cci_exp_inflation_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=gre_cci_exp_inflation_quarters['cci'],x=gre_cci_exp_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_cci_exp_inflation_quarters.exp_inflation.corr(gre_cci_exp_inflation_quarters.cci))

plt.close()
sns.lineplot(y=gre_cci_exp_inflation['exp_inflation'],x=gre_cci_exp_inflation['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=gre_cci_exp_inflation['cci'],x=gre_cci_exp_inflation['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_cci_exp_inflation.exp_inflation.corr(gre_cci_exp_inflation.cci))

plt.close()
sns.lineplot(y=gre_taylor_rule_cci_quarters['interest_rate'],x=gre_taylor_rule_cci_quarters['quarter'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=gre_taylor_rule_cci_quarters['cci'],x=gre_taylor_rule_cci_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_taylor_rule_cci_quarters['interest_rate'].corr(gre_taylor_rule_cci_quarters['cci']))

plt.close()
sns.lineplot(y=gre_taylor_rule_cci['interest_rate'],x=gre_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=gre_taylor_rule_cci['cci'],x=gre_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',gre_taylor_rule_cci['interest_rate'].corr(gre_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=gre_taylor_rule_cci['interest_rate'],x=gre_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=gre_taylor_rule_cci['output_gap'],x=gre_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.show()
print('corr:',gre_taylor_rule_cci['interest_rate'].corr(gre_taylor_rule_cci['output_gap']))

plt.close()
sns.lineplot(y=gre_taylor_rule_exp_quarters['exp_inflation'],x=gre_taylor_rule_exp_quarters['quarter'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=gre_taylor_rule_exp_quarters['interest_rate'],x=gre_taylor_rule_exp_quarters['quarter'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',gre_taylor_rule_exp_quarters['exp_inflation'].corr(gre_taylor_rule_exp_quarters['interest_rate']))

plt.close()
sns.lineplot(y=gre_taylor_rule_exp['exp_inflation'],x=gre_taylor_rule_exp['year'],color='black',label='expected inflation').legend(loc='upper left')
sns.lineplot(y=gre_taylor_rule_exp['interest_rate'],x=gre_taylor_rule_exp['year'],ax=plt.twinx(),color='green',label='interest rate').legend()
plt.show()
print('corr:',gre_taylor_rule_exp['exp_inflation'].corr(gre_taylor_rule_exp['interest_rate']))
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/129097126.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  gre_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/129097126.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  gre_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/129097126.py:19: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  gre_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/129097126.py:26: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  gre_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/129097126.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  gre_interest_rate.drop(columns=['Subject','Country'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/129097126.py:67: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  gre_output_gap['year']=pd.to_datetime(gre_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/129097126.py:93: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  gre_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Period: 1995 : 2024
Observations: 30
Mean: -1.2548242109707666
Median: -0.4148225375620925
Max: 7.16178248285473
Min: -11.2158352999479
Standard Deviation: 4.287597968626369
Skewness: -0.3859216207950702
Kurtosis: 0.33919634717913194
Jarque_beraResult(statistic=0.68157530725112, pvalue=0.7112099150198878)
Period: 1985 : 2023
Observations: 460
Mean: 99.9999997826087
Median: 100.74585
Max: 104.4815
Min: 93.6215
Standard Deviation: 2.557578717465192
Skewness: -0.748077363168076
Kurtosis: -0.34506430944997435
Jarque_beraResult(statistic=45.03108212491653, pvalue=1.665807491946225e-10)
Period: 1985Q1 : 2023Q2
Observations: 154
Mean: 99.99336770562763
Median: 100.71311666666665
Max: 104.31139999999999
Min: 93.68356999999999
Standard Deviation: 2.5502275336721554
Skewness: -0.753723864354521
Kurtosis: -0.3314961544694568
Jarque_beraResult(statistic=15.127271552965746, pvalue=0.000518984896445529)
Period: 1985 : 2023
Observations: 39
Mean: 99.97263914529915
Median: 100.74049000000001
Max: 103.524825
Min: 94.3237125
Standard Deviation: 2.484190039889193
Skewness: -0.8079588889375147
Kurtosis: -0.2870258684995517
Jarque_beraResult(statistic=4.181635215849104, pvalue=0.12358604956513697)
Period: 1997 : 2023
Observations: 317
Mean: 2.395899053627762
Median: 2.8
Max: 12.1
Min: -2.9
Standard Deviation: 2.5586566075476407
Skewness: 0.5410393778765759
Kurtosis: 1.3341746423070187
Jarque_beraResult(statistic=37.44802543837619, pvalue=7.383539446514931e-09)
Period: 1997Q1 : 2023Q2
Observations: 106
Mean: 2.4018867924528307
Median: 2.8333333333333335
Max: 11.533333333333333
Min: -2.233333333333333
Standard Deviation: 2.5405070951070985
Skewness: 0.5321199580641335
Kurtosis: 1.3213432473303066
Jarque_beraResult(statistic=11.261123930498579, pvalue=0.0035865592392423373)
Period: 1996 : 2022
Observations: 27
Mean: 2.5333333333333337
Median: 3.0
Max: 9.3
Min: -1.4
Standard Deviation: 2.6229754097208002
Skewness: 0.6107690504533966
Kurtosis: 0.619964559845239
Jarque_beraResult(statistic=1.59356406019557, pvalue=0.4507772201723784)
corr: 0.5465235357149822
corr: 0.24044718849601915
corr: 0.24461520428589734
corr: 0.3314396897036187
corr: 0.174605752658979
corr: -0.0018140455596834292
corr: 0.5711938101300612
corr: 0.6020954797716008
corr: 0.3627580787037638
corr: 0.3874329646165711
corr: 0.19153615826677847
In [437]:
gre_taylor_rule_exp_quarters.head()
Out[437]:
quarter interest_rate prev_int_rate exp_inflation exp_infl_2y exp_infl_dev output_gap
0 1999.4 10.359480 10.057420 1.15 NaN -0.85 -0.050973
1 2000.1 8.914449 10.359480 1.46 NaN -0.54 -0.169645
2 2000.2 8.532404 8.914449 1.49 NaN -0.51 -0.169645
3 2000.3 7.929986 8.532404 1.52 NaN -0.48 -0.169645
4 2000.4 6.161753 7.929986 1.64 1.5 -0.36 -0.169645
In [426]:
gre_taylor_rule_quarters.loc[47:91]
Out[426]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
47 2008Q4 4.214667 4.981800 3.066667 1.148000 1.066667 6.381754
48 2009Q1 2.011700 4.214667 1.766667 0.245033 -0.233333 2.474776
49 2009Q2 1.310633 2.011700 0.833333 0.477300 -1.166667 2.474776
50 2009Q3 0.869200 1.310633 0.800000 0.069200 -1.200000 2.474776
51 2009Q4 0.721900 0.869200 1.933333 -1.211433 -0.066667 2.474776
52 2010Q1 0.662133 0.721900 3.033333 -2.371200 1.033333 -0.508117
53 2010Q2 0.686267 0.662133 5.100000 -4.413733 3.100000 -0.508117
54 2010Q3 0.874933 0.686267 5.600000 -4.725067 3.600000 -0.508117
55 2010Q4 1.020467 0.874933 5.066667 -4.046200 3.066667 -0.508117
56 2011Q1 1.093133 1.020467 4.433333 -3.340200 2.433333 -6.729784
57 2011Q2 1.411633 1.093133 3.300000 -1.888367 1.300000 -6.729784
58 2011Q3 1.562067 1.411633 2.133333 -0.571266 0.133333 -6.729784
59 2011Q4 1.495567 1.562067 2.633333 -1.137766 0.633333 -6.729784
60 2012Q1 1.043000 1.495567 1.700000 -0.657000 -0.300000 -9.521065
61 2012Q2 0.696033 1.043000 1.133333 -0.437300 -0.866667 -9.521065
62 2012Q3 0.358567 0.696033 0.766667 -0.408100 -1.233333 -9.521065
63 2012Q4 0.195133 0.358567 0.533333 -0.338200 -1.466667 -9.521065
64 2013Q1 0.211467 0.195133 -0.033333 0.244800 -2.033333 -8.425382
65 2013Q2 0.206800 0.211467 -0.366667 0.573467 -2.366667 -8.425382
66 2013Q3 0.223500 0.206800 -0.833333 1.056833 -2.833333 -8.425382
67 2013Q4 0.240900 0.223500 -2.200000 2.440900 -4.200000 -8.425382
68 2014Q1 0.295133 0.240900 -1.266667 1.561800 -3.266667 -5.636071
69 2014Q2 0.298567 0.295133 -1.733333 2.031900 -3.733333 -5.636071
70 2014Q3 0.164567 0.298567 -0.700000 0.864567 -2.700000 -5.636071
71 2014Q4 0.081467 0.164567 -1.833333 1.914800 -3.833333 -5.636071
72 2015Q1 0.046033 0.081467 -2.200000 2.246033 -4.200000 -4.349528
73 2015Q2 -0.006533 0.046033 -1.433333 1.426800 -3.433333 -4.349528
74 2015Q3 -0.027800 -0.006533 -0.833333 0.805533 -2.833333 -4.349528
75 2015Q4 -0.089167 -0.027800 0.066667 -0.155833 -1.933333 -4.349528
76 2016Q1 -0.186067 -0.089167 -0.233333 0.047267 -2.233333 -3.993883
77 2016Q2 -0.258100 -0.186067 -0.133333 -0.124767 -2.133333 -3.993883
78 2016Q3 -0.298100 -0.258100 0.166667 -0.464767 -1.833333 -3.993883
79 2016Q4 -0.312500 -0.298100 0.233333 -0.545833 -1.766667 -3.993883
80 2017Q1 -0.327800 -0.312500 1.533333 -1.861133 -0.466667 -2.949444
81 2017Q2 -0.329967 -0.327800 1.333333 -1.663300 -0.666667 -2.949444
82 2017Q3 -0.329633 -0.329967 0.833333 -1.162967 -1.166667 -2.949444
83 2017Q4 -0.328800 -0.329633 0.866667 -1.195467 -1.133333 -2.949444
84 2018Q1 -0.328300 -0.328800 0.266667 -0.594967 -1.733333 -2.054161
85 2018Q2 -0.325233 -0.328300 0.766667 -1.091900 -1.233333 -2.054161
86 2018Q3 -0.319500 -0.325233 0.933333 -1.252833 -1.066667 -2.054161
87 2018Q4 -0.315333 -0.319500 1.166667 -1.482000 -0.833333 -2.054161
88 2019Q1 -0.308533 -0.315333 0.766667 -1.075200 -1.233333 -1.268119
89 2019Q2 -0.317100 -0.308533 0.633333 -0.950433 -1.366667 -1.268119
90 2019Q3 -0.396733 -0.317100 0.233333 -0.630067 -1.766667 -1.268119
91 2019Q4 -0.402967 -0.396733 0.433333 -0.836300 -1.566667 -1.268119

UK¶

In [430]:
uk_output_gap=oecd_output_gap[oecd_output_gap['Country']=='United Kingdom']
uk_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
uk_output_gap.reset_index(drop=True,inplace=True)
uk_output_gap.columns=['year','output_gap']

uk_cci=oecd_cci[oecd_cci['Country']=='United Kingdom']
uk_cci.drop(columns=['Country','Subject'],inplace=True)
uk_cci.reset_index(drop=True,inplace=True)
uk_cci.columns=['month','cci']

uk_cci_year=uk_cci.resample('Y',on='month').mean().reset_index()
uk_cci_year['year'] = uk_cci_year['month'].dt.year
uk_cci_year.drop(columns='month',inplace=True)
uk_cci_year=uk_cci_year[['year', 'cci']]

uk_cci_og=uk_output_gap.merge(uk_cci_year,on='year',how='inner')

uk_inflation=oecd_hicp[oecd_hicp['Country']=='United Kingdom']
uk_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
uk_inflation.reset_index(drop=True,inplace=True)
uk_inflation.columns=['month','inflation']

uk_cci_inflation=uk_inflation.merge(uk_cci,on='month',how='inner')

uk_inflation_year=oecd_hicp_year[oecd_hicp_year['Country']=='United Kingdom']
uk_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
uk_inflation_year.reset_index(drop=True,inplace=True)
uk_inflation_year.columns=['year','inflation']

uk_cci_inflation_year=uk_inflation_year.merge(uk_cci_year,on='year',how='inner')

uk_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='United Kingdom']

uk_interest_rate.drop(columns=['Subject','Country'],inplace=True)
uk_interest_rate.reset_index(drop=True,inplace=True)
uk_interest_rate.columns=['year','interest_rate']

uk_taylor_rule=uk_interest_rate.merge(uk_inflation_year,on='year',how='inner')
uk_taylor_rule['real_interest_rate']=uk_taylor_rule['interest_rate']-uk_taylor_rule['inflation']
uk_taylor_rule['infl_dev']=uk_inflation_year['inflation']-2
uk_taylor_rule=uk_taylor_rule.merge(uk_output_gap,on='year',how='inner')
uk_taylor_rule_cci=uk_taylor_rule.merge(uk_cci_year,on='year',how='inner')
uk_taylor_rule_cci=uk_taylor_rule_cci[uk_taylor_rule_cci['year']<2023]
uk_taylor_rule.to_csv('uk_taylor.csv',index=False)
uk_taylor_rule_pre_gr=uk_taylor_rule[uk_taylor_rule['year']<2008]
uk_taylor_rule_pre_gr.to_csv('uk_taylor_pre_gr.csv',index=False)

uk_taylor_rule_post_gr=uk_taylor_rule[(uk_taylor_rule['year']<2020)&(uk_taylor_rule['year']>2007)]
uk_taylor_rule_post_gr.to_csv('uk_taylor_post_gr.csv',index=False)

uk_output_gap['year']=pd.to_datetime(uk_output_gap['year'],format='%Y')
uk_og_quarters=uk_output_gap.resample('Q',on='year').mean().reset_index()
uk_og_quarters['year']=uk_og_quarters['year'].dt.to_period('Q')
uk_og_quarters.columns=['quarter','output_gap']
uk_og_quarters['output_gap']=uk_og_quarters['output_gap'].ffill()
uk_og_quarters.quarter=uk_og_quarters.quarter.astype(str)

uk_cci_quarters=uk_cci.resample('Q',on='month').mean().reset_index()
uk_cci_quarters['month']=uk_cci_quarters['month'].dt.to_period('Q')
uk_cci_quarters.columns=['quarter','cci']
uk_cci_quarters.quarter=uk_cci_quarters.quarter.astype(str)

uk_inflation_quarters=uk_inflation.resample('Q',on='month').mean().reset_index()
uk_inflation_quarters['month']=uk_inflation_quarters['month'].dt.to_period('Q')
uk_inflation_quarters.columns=['quarter','inflation']
uk_inflation_quarters.quarter=uk_inflation_quarters.quarter.astype(str)

uk_cci_inflation_quarters=uk_inflation_quarters.merge(uk_cci_quarters,on='quarter',how='inner')
uk_cci_inflation_quarters.quarter=pd.to_datetime(uk_cci_inflation_quarters.quarter).dt.to_period('Q')
uk_cci_inflation_quarters.quarter=uk_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

uk_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='United Kingdom']
uk_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
uk_interest_rate_quarters.reset_index(drop=True,inplace=True)
uk_interest_rate_quarters.columns=['quarter','interest_rate']
uk_interest_rate_quarters=uk_interest_rate_quarters.replace('-', '',regex=True)
uk_interest_rate_quarters.quarter=uk_interest_rate_quarters.quarter.astype(str)
uk_interest_rate_quarters['prev_int_rate']=uk_interest_rate_quarters['interest_rate'].shift(1)

uk_taylor_rule_quarters=uk_interest_rate_quarters.merge(uk_inflation_quarters,on='quarter',how='inner')
uk_taylor_rule_quarters['real_interest_rate']=uk_taylor_rule_quarters['interest_rate']-uk_taylor_rule_quarters['inflation']
uk_taylor_rule_quarters['infl_dev']=uk_taylor_rule_quarters['inflation']-2
uk_taylor_rule_quarters=uk_taylor_rule_quarters.merge(uk_og_quarters,on='quarter',how='inner')
uk_taylor_rule_cci_quarters=uk_taylor_rule_quarters.merge(uk_cci_quarters,on='quarter',how='inner')
uk_taylor_rule_cci_quarters.quarter=pd.to_datetime(uk_taylor_rule_cci_quarters.quarter).dt.to_period('Q')
uk_taylor_rule_cci_quarters.quarter=uk_taylor_rule_cci_quarters.quarter.dt.strftime('%Y.%q').astype(float)
uk_taylor_rule_quarters.to_csv('uk_taylor_quarters.csv',index=False)

uk_taylor_rule_quarters_pre_gr=uk_taylor_rule_quarters.loc[:79]
uk_taylor_rule_quarters_pre_gr.to_csv('uk_taylor_quart_pre_gr.csv',index=False)

uk_taylor_rule_quarters_post_gr=uk_taylor_rule_quarters.loc[80:123]
uk_taylor_rule_quarters_post_gr.to_csv('uk_taylor_quart_post_gr.csv',index=False)

plt.close()
sns.histplot(x=uk_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(uk_output_gap)

plt.close()
sns.histplot(x=uk_cci['cci'],bins=20)
plt.show()
summary_stat(uk_cci)

plt.close()
sns.histplot(x=uk_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(uk_cci_quarters)

plt.close()
sns.histplot(x=uk_cci_year['cci'],bins=20)
plt.show()
summary_stat(uk_cci_year)

plt.close()
sns.histplot(x=uk_inflation['inflation'],bins=20)
plt.show()
summary_stat(uk_inflation)

plt.close()
sns.histplot(x=uk_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(uk_inflation_quarters)

plt.close()
sns.histplot(x=uk_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(uk_inflation_year)

plt.close()
sns.lineplot(y=uk_cci_og['output_gap'],x=uk_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=uk_cci_og['cci'],x=uk_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',uk_cci_og.output_gap.corr(uk_cci_og.cci))

plt.close()
sns.lineplot(y=uk_cci_inflation['inflation'],x=uk_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=uk_cci_inflation['cci'],x=uk_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',uk_cci_inflation.inflation.corr(uk_cci_inflation.cci))

plt.close()
sns.lineplot(y=uk_cci_inflation_quarters['inflation'],x=uk_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=uk_cci_inflation_quarters['cci'],x=uk_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',uk_cci_inflation_quarters.inflation.corr(uk_cci_inflation_quarters.cci))

plt.close()
sns.lineplot(y=uk_cci_inflation_year['inflation'],x=uk_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=uk_cci_inflation_year['cci'],x=uk_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',uk_cci_inflation_year.inflation.corr(uk_cci_inflation_year.cci))

plt.close()
sns.lineplot(y=uk_taylor_rule_cci_quarters['interest_rate'],x=uk_taylor_rule_cci_quarters['quarter'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=uk_taylor_rule_cci_quarters['cci'],x=uk_taylor_rule_cci_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',uk_taylor_rule_cci_quarters['interest_rate'].corr(uk_taylor_rule_cci_quarters['cci']))

plt.close()
sns.lineplot(y=uk_taylor_rule_cci['interest_rate'],x=uk_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=uk_taylor_rule_cci['cci'],x=uk_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',uk_taylor_rule_cci['interest_rate'].corr(uk_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=uk_taylor_rule_cci['interest_rate'],x=uk_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=uk_taylor_rule_cci['output_gap'],x=uk_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.show()
print('corr:',uk_taylor_rule_cci['interest_rate'].corr(uk_taylor_rule_cci['output_gap']))
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2118651517.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  uk_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2118651517.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  uk_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2118651517.py:19: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  uk_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2118651517.py:26: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  uk_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2118651517.py:34: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  uk_interest_rate.drop(columns=['Subject','Country'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2118651517.py:51: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  uk_output_gap['year']=pd.to_datetime(uk_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/2118651517.py:73: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  uk_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Period: 1985 : 2024
Observations: 40
Mean: -1.180338215405677
Median: -1.63158535181014
Max: 8.40195393770722
Min: -13.7414125424186
Standard Deviation: 3.9018014668549794
Skewness: 0.05952321155119926
Kurtosis: 2.654869214731032
Jarque_beraResult(statistic=8.001382125231775, pvalue=0.01830298600788205)
Period: 1974 : 2023
Observations: 592
Mean: 99.99999854729727
Median: 100.5349
Max: 105.5421
Min: 92.03677
Standard Deviation: 2.3439756651019454
Skewness: -0.5412412735136986
Kurtosis: 0.183405467469266
Jarque_beraResult(statistic=29.484785195722406, pvalue=3.957858329961539e-07)
Period: 1974Q1 : 2023Q2
Observations: 198
Mean: 99.98715047138055
Median: 100.48176666666666
Max: 105.49073333333332
Min: 92.50532
Standard Deviation: 2.3357389290492283
Skewness: -0.5343669671678386
Kurtosis: 0.15567780688306954
Jarque_beraResult(statistic=9.402589647462205, pvalue=0.009083507942201363)
Period: 1974 : 2023
Observations: 50
Mean: 99.92967673333334
Median: 100.36945333333333
Max: 104.43470833333333
Min: 94.08241166666666
Standard Deviation: 2.250130091976468
Skewness: -0.5740058904160853
Kurtosis: -0.08296256128748158
Jarque_beraResult(statistic=2.659303552628907, pvalue=0.26456937458357976)
Period: 1989 : 2023
Observations: 412
Mean: 2.7643203883495153
Median: 2.2
Max: 11.1
Min: -0.1
Standard Deviation: 2.1576692332173137
Skewness: 1.724830029082248
Kurtosis: 2.893643430372252
Jarque_beraResult(statistic=341.66093166773413, pvalue=0.0)
Period: 1989Q1 : 2023Q2
Observations: 138
Mean: 2.7929951690821286
Median: 2.25
Max: 10.766666666666666
Min: 0.0
Standard Deviation: 2.187327851267446
Skewness: 1.7203192987159852
Kurtosis: 2.8128574071184076
Jarque_beraResult(statistic=107.5468206192013, pvalue=0.0)
Period: 1996 : 2022
Observations: 27
Mean: 2.245081355555556
Median: 2.1
Max: 9.053559
Min: 0.0
Standard Deviation: 1.6702335219822724
Skewness: 2.7228030239563403
Kurtosis: 10.46316819180046
Jarque_beraResult(statistic=109.25621004579888, pvalue=0.0)
corr: 0.20821355825890595
corr: -0.663158551328091
corr: -0.6742087436254499
corr: -0.7786736179469979
corr: 0.00027822950340974467
corr: 0.4206470926527181
corr: 0.4705977217294618
In [429]:
uk_taylor_rule_quarters.loc[80:123]
Out[429]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
79 2008Q4 4.584116 5.836330 3.900000 0.684116 1.900000 0.266804
80 2009Q1 2.088177 4.584116 3.033333 -0.945156 1.033333 -5.189876
81 2009Q2 1.377750 2.088177 2.100000 -0.722250 0.100000 -5.189876
82 2009Q3 0.793473 1.377750 1.500000 -0.706527 -0.500000 -5.189876
83 2009Q4 0.595213 0.793473 2.100000 -1.504787 0.100000 -5.189876
84 2010Q1 0.630413 0.595213 3.300000 -2.669587 1.300000 -3.762048
85 2010Q2 0.693813 0.630413 3.433333 -2.739520 1.433333 -3.762048
86 2010Q3 0.732527 0.693813 3.100000 -2.367473 1.100000 -3.762048
87 2010Q4 0.742343 0.732527 3.400000 -2.657657 1.400000 -3.762048
88 2011Q1 0.792470 0.742343 4.133333 -3.340863 2.133333 -3.767528
89 2011Q2 0.823173 0.792470 4.400000 -3.576827 2.400000 -3.767528
90 2011Q3 0.868273 0.823173 4.700000 -3.831727 2.700000 -3.767528
91 2011Q4 1.014403 0.868273 4.666667 -3.652264 2.666667 -3.767528
92 2012Q1 1.065717 1.014403 3.500000 -2.434283 1.500000 -3.620530
93 2012Q2 0.990900 1.065717 2.733333 -1.742433 0.733333 -3.620530
94 2012Q3 0.723397 0.990900 2.433333 -1.709937 0.433333 -3.620530
95 2012Q4 0.528990 0.723397 2.700000 -2.171010 0.700000 -3.620530
96 2013Q1 0.509680 0.528990 2.766667 -2.256987 0.766667 -3.310407
97 2013Q2 0.506380 0.509680 2.666667 -2.160287 0.666667 -3.310407
98 2013Q3 0.512980 0.506380 2.733333 -2.220353 0.733333 -3.310407
99 2013Q4 0.521603 0.512980 2.100000 -1.578397 0.100000 -3.310407
100 2014Q1 0.521343 0.521603 1.733333 -1.211990 -0.266667 -1.957777
101 2014Q2 0.532677 0.521343 1.733333 -1.200657 -0.266667 -1.957777
102 2014Q3 0.560170 0.532677 1.433333 -0.873163 -0.566667 -1.957777
103 2014Q4 0.557607 0.560170 0.933333 -0.375727 -1.066667 -1.957777
104 2015Q1 0.563530 0.557607 0.100000 0.463530 -1.900000 -1.579435
105 2015Q2 0.569787 0.563530 0.000000 0.569787 -2.000000 -1.579435
106 2015Q3 0.584433 0.569787 0.000000 0.584433 -2.000000 -1.579435
107 2015Q4 0.578847 0.584433 0.066667 0.512180 -1.933333 -1.579435
108 2016Q1 0.589580 0.578847 0.366667 0.222913 -1.633333 -1.563560
109 2016Q2 0.584290 0.589580 0.366667 0.217623 -1.633333 -1.563560
110 2016Q3 0.432933 0.584290 0.733333 -0.300400 -1.266667 -1.563560
111 2016Q4 0.389163 0.432933 1.233333 -0.844170 -0.766667 -1.563560
112 2017Q1 0.354837 0.389163 2.133333 -1.778497 0.133333 -1.264804
113 2017Q2 0.313453 0.354837 2.733333 -2.419880 0.733333 -1.264804
114 2017Q3 0.294467 0.313453 2.833333 -2.538867 0.833333 -1.264804
115 2017Q4 0.473050 0.294467 3.033333 -2.560283 1.033333 -1.264804
116 2018Q1 0.565917 0.473050 2.733333 -2.167417 0.733333 -1.571029
117 2018Q2 0.679507 0.565917 2.400000 -1.720493 0.400000 -1.571029
118 2018Q3 0.784103 0.679507 2.533333 -1.749230 0.533333 -1.571029
119 2018Q4 0.861817 0.784103 2.266667 -1.404850 0.266667 -1.571029
120 2019Q1 0.878067 0.861817 1.866667 -0.988600 -0.133333 -1.747347
121 2019Q2 0.800000 0.878067 2.033333 -1.233333 0.033333 -1.747347
122 2019Q3 0.766667 0.800000 1.833333 -1.066667 -0.166667 -1.747347
123 2019Q4 0.786667 0.766667 1.433333 -0.646667 -0.566667 -1.747347
124 2020Q1 0.673333 0.786667 1.666667 -0.993333 -0.333333 -13.741413
125 2020Q2 0.390000 0.673333 0.633333 -0.243333 -1.366667 -13.741413
126 2020Q3 0.076667 0.390000 0.566667 -0.490000 -1.433333 -13.741413
127 2020Q4 0.040000 0.076667 0.533333 -0.493333 -1.466667 -13.741413
128 2021Q1 0.053333 0.040000 0.600000 -0.546667 -1.400000 -5.887348
129 2021Q2 0.083333 0.053333 2.033333 -1.950000 0.033333 -5.887348
130 2021Q3 0.073333 0.083333 2.766667 -2.693333 0.766667 -5.887348
131 2021Q4 0.150000 0.073333 4.900000 -4.750000 2.900000 -5.887348
132 2022Q1 0.776667 0.150000 6.233333 -5.456667 4.233333 -2.701180
133 2022Q2 1.336667 0.776667 9.166667 -7.830000 7.166667 -2.701180
134 2022Q3 2.326667 1.336667 10.033333 -7.706666 8.033333 -2.701180
135 2022Q4 3.563333 2.326667 10.766667 -7.203334 8.766667 -2.701180
136 2023Q1 4.183333 3.563333 10.200000 -6.016667 8.200000 -3.996599

Japan¶

In [436]:
jap_output_gap=oecd_output_gap[oecd_output_gap['Country']=='Japan']
jap_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
jap_output_gap.reset_index(drop=True,inplace=True)
jap_output_gap.columns=['year','output_gap']

jap_cci=oecd_cci[oecd_cci['Country']=='Japan']
jap_cci.drop(columns=['Country','Subject'],inplace=True)
jap_cci.reset_index(drop=True,inplace=True)
jap_cci.columns=['month','cci']

jap_cci_year=jap_cci.resample('Y',on='month').mean().reset_index()
jap_cci_year['year'] = jap_cci_year['month'].dt.year
jap_cci_year.drop(columns='month',inplace=True)
jap_cci_year=jap_cci_year[['year', 'cci']]

jap_cci_og=jap_output_gap.merge(jap_cci_year,on='year',how='inner')

jap_inflation=oecd_inflation[oecd_inflation['Country']=='Japan']
jap_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
jap_inflation.reset_index(drop=True,inplace=True)
jap_inflation.columns=['month','inflation']

jap_cci_inflation=jap_inflation.merge(jap_cci,on='month',how='inner')
jap_cci_inflation.inflation.corr(jap_cci_inflation.cci)

jap_inflation_year=oecd_inflation_year[oecd_inflation_year['Country']=='Japan']
jap_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
jap_inflation_year.reset_index(drop=True,inplace=True)
jap_inflation_year.columns=['year','inflation']

jap_cci_inflation_year=jap_inflation_year.merge(jap_cci_year,on='year',how='inner')

jap_interest_rate=oecd_interest_rate[oecd_interest_rate['Country']=='Japan']

jap_interest_rate.drop(columns=['Subject','Country'],inplace=True)
jap_interest_rate.reset_index(drop=True,inplace=True)
jap_interest_rate.columns=['year','interest_rate']

jap_taylor_rule=jap_interest_rate.merge(jap_inflation_year,on='year',how='inner')
jap_taylor_rule['real_interest_rate']=jap_taylor_rule['interest_rate']-jap_taylor_rule['inflation']
jap_taylor_rule['infl_dev']=jap_inflation_year['inflation']-2
jap_taylor_rule=jap_taylor_rule.merge(jap_output_gap,on='year',how='inner')
jap_taylor_rule_cci=jap_taylor_rule.merge(jap_cci_year,on='year',how='inner')
jap_taylor_rule.to_csv('jap_taylor.csv',index=False)

jap_taylor_rule_pre_gr=jap_taylor_rule[jap_taylor_rule['year']<2008]
jap_taylor_rule_pre_gr.to_csv('jap_taylor_pre_gr.csv',index=False)

jap_taylor_rule_post_gr=jap_taylor_rule[(jap_taylor_rule['year']<2020)&(jap_taylor_rule['year']>2007)]
jap_taylor_rule_post_gr.to_csv('jap_taylor_post_gr.csv',index=False)

jap_output_gap['year']=pd.to_datetime(jap_output_gap['year'],format='%Y')
jap_og_quarters=jap_output_gap.resample('Q',on='year').mean().reset_index()
jap_og_quarters['year']=jap_og_quarters['year'].dt.to_period('Q')
jap_og_quarters.columns=['quarter','output_gap']
jap_og_quarters['output_gap']=jap_og_quarters['output_gap'].ffill()
jap_og_quarters.quarter=jap_og_quarters.quarter.astype(str)

jap_cci_quarters=jap_cci.resample('Q',on='month').mean().reset_index()
jap_cci_quarters['month']=jap_cci_quarters['month'].dt.to_period('Q')
jap_cci_quarters.columns=['quarter','cci']
jap_cci_quarters.quarter=jap_cci_quarters.quarter.astype(str)

jap_inflation_quarters=oecd_inflation_quarters[oecd_inflation_quarters['Country']=='Japan']
jap_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
jap_inflation_quarters.reset_index(drop=True,inplace=True)
jap_inflation_quarters.columns=['quarter','inflation']
jap_inflation_quarters=jap_inflation_quarters.replace('-', '',regex=True)

jap_cci_inflation_quarters=jap_inflation_quarters.merge(jap_cci_quarters,on='quarter',how='inner')
jap_cci_inflation_quarters.quarter=pd.to_datetime(jap_cci_inflation_quarters.quarter).dt.to_period('Q')
jap_cci_inflation_quarters.quarter=jap_cci_inflation_quarters.quarter.dt.strftime('%Y.%q').astype(float)

jap_interest_rate_quarters=oecd_interest_rate_quarters[oecd_interest_rate_quarters['Country']=='Japan']
jap_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
jap_interest_rate_quarters.reset_index(drop=True,inplace=True)
jap_interest_rate_quarters.columns=['quarter','interest_rate']
jap_interest_rate_quarters=jap_interest_rate_quarters.replace('-', '',regex=True)
jap_interest_rate_quarters.quarter=jap_interest_rate_quarters.quarter.astype(str)
jap_interest_rate_quarters['prev_int_rate']=jap_interest_rate_quarters['interest_rate'].shift(1)

jap_taylor_rule_quarters=jap_interest_rate_quarters.merge(jap_inflation_quarters,on='quarter',how='inner')
jap_taylor_rule_quarters['real_interest_rate']=jap_taylor_rule_quarters['interest_rate']-jap_taylor_rule_quarters['inflation']
jap_taylor_rule_quarters['infl_dev']=jap_taylor_rule_quarters['inflation']-2
jap_taylor_rule_quarters=jap_taylor_rule_quarters.merge(jap_og_quarters,on='quarter',how='inner')
jap_taylor_rule_cci_quarters=jap_taylor_rule_quarters.merge(jap_cci_quarters,on='quarter',how='inner')
jap_taylor_rule_cci_quarters.quarter=pd.to_datetime(jap_taylor_rule_cci_quarters.quarter).dt.to_period('Q')
jap_taylor_rule_cci_quarters.quarter=jap_taylor_rule_cci_quarters.quarter.dt.strftime('%Y.%q').astype(float)
jap_taylor_rule_quarters.to_csv('jap_taylor_quarters.csv',index=False)

jap_taylor_rule_quarters_pre_gr=jap_taylor_rule_quarters.loc[:26]
jap_taylor_rule_quarters_pre_gr.to_csv('jap_taylor_quart_pre_gr.csv',index=False)

jap_taylor_rule_quarters_post_gr=jap_taylor_rule_quarters.loc[27:70]
jap_taylor_rule_quarters_post_gr.to_csv('jap_taylor_quart_post_gr.csv',index=False)

plt.close()
sns.histplot(x=jap_output_gap['output_gap'],bins=20)
plt.show()
summary_stat(jap_output_gap)

plt.close()
sns.histplot(x=jap_cci['cci'],bins=20)
plt.show()
summary_stat(jap_cci)

plt.close()
sns.histplot(x=jap_cci_quarters['cci'],bins=20)
plt.show()
summary_stat(jap_cci_quarters)

plt.close()
sns.histplot(x=jap_cci_year['cci'],bins=20)
plt.show()
summary_stat(jap_cci_year)

plt.close()
sns.histplot(x=jap_inflation['inflation'],bins=20)
plt.show()
summary_stat(jap_inflation)

plt.close()
sns.histplot(x=jap_inflation_quarters['inflation'],bins=20)
plt.show()
summary_stat(jap_inflation_quarters)

plt.close()
sns.histplot(x=jap_inflation_year['inflation'],bins=20)
plt.show()
summary_stat(jap_inflation_year)

plt.close()
sns.lineplot(y=jap_cci_og['output_gap'],x=jap_cci_og['year'],color='black',label='output gap').legend(loc='upper left')
sns.lineplot(y=jap_cci_og['cci'],x=jap_cci_og['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',jap_cci_og.output_gap.corr(jap_cci_og.cci))

plt.close()
sns.lineplot(y=jap_cci_inflation['inflation'],x=jap_cci_inflation['month'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=jap_cci_inflation['cci'],x=jap_cci_inflation['month'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',jap_cci_inflation.inflation.corr(jap_cci_inflation.cci))

plt.close()
sns.lineplot(y=jap_cci_inflation_quarters['inflation'],x=jap_cci_inflation_quarters['quarter'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=jap_cci_inflation_quarters['cci'],x=jap_cci_inflation_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',jap_cci_inflation_quarters.inflation.corr(jap_cci_inflation_quarters.cci))

plt.close()
sns.lineplot(y=jap_cci_inflation_year['inflation'],x=jap_cci_inflation_year['year'],color='black',label='inflation').legend(loc='upper left')
sns.lineplot(y=jap_cci_inflation_year['cci'],x=jap_cci_inflation_year['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.show()
print('corr:',jap_cci_inflation_year.inflation.corr(jap_cci_inflation_year.cci))

from  matplotlib.ticker import FuncFormatter

plt.close()
sns.lineplot(y=jap_taylor_rule_cci_quarters['interest_rate'],x=jap_taylor_rule_cci_quarters['quarter'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=jap_taylor_rule_cci_quarters['cci'],x=jap_taylor_rule_cci_quarters['quarter'],ax=plt.twinx(),color='red',label='cci').legend()
plt.gca().xaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
plt.show()
print('corr:',jap_taylor_rule_cci_quarters['interest_rate'].corr(jap_taylor_rule_cci_quarters['cci']))

plt.close()
sns.lineplot(y=jap_taylor_rule_cci['interest_rate'],x=jap_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=jap_taylor_rule_cci['cci'],x=jap_taylor_rule_cci['year'],ax=plt.twinx(),color='red',label='cci').legend()
plt.gca().xaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
plt.show()
print('corr:',jap_taylor_rule_cci['interest_rate'].corr(jap_taylor_rule_cci['cci']))

plt.close()
sns.lineplot(y=jap_taylor_rule_cci['interest_rate'],x=jap_taylor_rule_cci['year'],color='green',label='interest rate').legend(loc='upper left')
sns.lineplot(y=jap_taylor_rule_cci['output_gap'],x=jap_taylor_rule_cci['year'],ax=plt.twinx(),color='black',label='output gap').legend()
plt.gca().xaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
plt.show()
print('corr:',jap_taylor_rule_cci['interest_rate'].corr(jap_taylor_rule_cci['output_gap']))
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_output_gap.drop(columns=['Country','Variable','Unit'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_cci.drop(columns=['Country','Subject'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:19: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_inflation.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:27: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_inflation_year.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:35: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_interest_rate.drop(columns=['Subject','Country'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:52: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_output_gap['year']=pd.to_datetime(jap_output_gap['year'],format='%Y')
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:65: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_inflation_quarters.drop(columns=['Country','Subject','Measure'],inplace=True)
/var/folders/69/63fffhrd75q2z1lmnq84pl340000gn/T/ipykernel_19832/745836761.py:75: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  jap_interest_rate_quarters.drop(columns=['Subject','Country'],inplace=True)
Period: 1985 : 2024
Observations: 40
Mean: -0.03940093891573572
Median: 0.083059074404007
Max: 4.38933347164145
Min: -5.16790183789893
Standard Deviation: 2.1413270635688333
Skewness: -0.17311318641039158
Kurtosis: -0.16809754010094569
Jarque_beraResult(statistic=0.329138419843807, pvalue=0.8482590469703117)
Period: 1982 : 2023
Observations: 493
Mean: 99.99999862068971
Median: 100.0497
Max: 102.409
Min: 95.45394
Standard Deviation: 1.4297129193151439
Skewness: -0.5100720102495189
Kurtosis: -0.06286477010384228
Jarque_beraResult(statistic=21.361215375925124, pvalue=2.298640306430677e-05)
Period: 1982Q2 : 2023Q2
Observations: 165
Mean: 99.99270400000003
Median: 100.05097
Max: 102.3843
Min: 95.67483
Standard Deviation: 1.4253894112105245
Skewness: -0.48348705247628027
Kurtosis: -0.09919893192391305
Jarque_beraResult(statistic=6.43219979758539, pvalue=0.04011119130103502)
Period: 1982 : 2023
Observations: 42
Mean: 99.96274424603176
Median: 100.14830291666667
Max: 102.26721666666667
Min: 97.0077525
Standard Deviation: 1.3813696805583637
Skewness: -0.32974291939842415
Kurtosis: -0.6029452018734496
Jarque_beraResult(statistic=1.4999429174987182, pvalue=0.47238003486558844)
Period: 1956 : 2021
Observations: 786
Mean: 2.842131754707379
Median: 1.7
Max: 24.9
Min: -2.5
Standard Deviation: 4.077883560987086
Skewness: 2.3977464272655453
Kurtosis: 8.387790954477612
Jarque_beraResult(statistic=3021.0681211761275, pvalue=0.0)
Period: 1956Q1 : 2021Q2
Observations: 262
Mean: 2.8402757045801503
Median: 1.658715
Max: 23.48936
Min: -2.251791
Standard Deviation: 4.0649816583541885
Skewness: 2.4110471255021984
Kurtosis: 8.490510026602276
Jarque_beraResult(statistic=1004.1704100164457, pvalue=0.0)
Period: 1956 : 2020
Observations: 65
Mean: 2.8637128410769233
Median: 1.6
Max: 23.2
Min: -1.4
Standard Deviation: 4.0108351101156305
Skewness: 2.4754106265726814
Kurtosis: 9.45294130152175
Jarque_beraResult(statistic=265.9969816601277, pvalue=0.0)
corr: 0.6800197370758823
corr: 0.34766561064119794
corr: 0.35284899494743344
corr: 0.40118495129785303
corr: -0.13407135221324934
corr: -0.2004900672180824
corr: -0.06327421597308588
In [435]:
jap_taylor_rule_quarters.loc[27:]
Out[435]:
quarter interest_rate prev_int_rate inflation real_interest_rate infl_dev output_gap
27 2009Q1 0.693333 0.836667 -0.104275 0.797609 -2.104275 -5.167902
28 2009Q2 0.576667 0.693333 -0.930713 1.507380 -2.930713 -5.167902
29 2009Q3 0.543333 0.576667 -2.251791 2.795124 -4.251791 -5.167902
30 2009Q4 0.500000 0.543333 -2.028188 2.528188 -4.028188 -5.167902
31 2010Q1 0.440000 0.500000 -0.869868 1.309868 -2.869868 -1.405042
32 2010Q2 0.390000 0.440000 -0.800278 1.190278 -2.800278 -1.405042
33 2010Q3 0.363333 0.390000 -1.012216 1.375549 -3.012216 -1.405042
34 2010Q4 0.340000 0.363333 -0.280702 0.620702 -2.280702 -1.405042
35 2011Q1 0.338717 0.340000 -0.526501 0.865217 -2.526501 -1.479907
36 2011Q2 0.332380 0.338717 -0.385829 0.718209 -2.385829 -1.479907
37 2011Q3 0.330000 0.332380 0.141044 0.188956 -1.858956 -1.479907
38 2011Q4 0.329290 0.330000 -0.316678 0.645968 -2.316678 -1.479907
39 2012Q1 0.331370 0.329290 0.317572 0.013798 -1.682428 -0.340465
40 2012Q2 0.332630 0.331370 0.176056 0.156574 -1.823944 -0.340465
41 2012Q3 0.327270 0.332630 -0.422535 0.749805 -2.422535 -0.340465
42 2012Q4 0.317573 0.327270 -0.247088 0.564661 -2.247088 -0.340465
43 2013Q1 0.270303 0.317573 -0.668308 0.938611 -2.668308 1.246789
44 2013Q2 0.228180 0.270303 -0.281195 0.509375 -2.281195 1.246789
45 2013Q3 0.228000 0.228180 0.884017 -0.656017 -1.115983 1.246789
46 2013Q4 0.220333 0.228000 1.415428 -1.195095 -0.584572 1.246789
47 2014Q1 0.214667 0.220333 1.522663 -1.307996 -0.477337 0.832342
48 2014Q2 0.210667 0.214667 3.560099 -3.349432 1.560099 0.832342
49 2014Q3 0.210000 0.210667 3.364879 -3.154879 1.364879 0.832342
50 2014Q4 0.184333 0.210000 2.581996 -2.397663 0.581996 0.832342
51 2015Q1 0.171333 0.184333 2.302058 -2.130725 0.302058 1.627259
52 2015Q2 0.169333 0.171333 0.578625 -0.409292 -1.421375 1.627259
53 2015Q3 0.169000 0.169333 0.101729 0.067271 -1.898271 1.627259
54 2015Q4 0.169000 0.169000 0.238095 -0.069095 -1.761905 1.627259
55 2016Q1 0.121667 0.169000 0.034095 0.087572 -1.965905 1.603716
56 2016Q2 0.059667 0.121667 -0.372250 0.431917 -2.372250 1.603716
57 2016Q3 0.057333 0.059667 -0.474255 0.531588 -2.474255 1.603716
58 2016Q4 0.056000 0.057333 0.305395 -0.249395 -1.694605 1.603716
59 2017Q1 0.056000 0.056000 0.340832 -0.284832 -1.659168 2.518019
60 2017Q2 0.056000 0.056000 0.407609 -0.351609 -1.592391 2.518019
61 2017Q3 0.062333 0.056000 0.612662 -0.550328 -1.387338 2.518019
62 2017Q4 0.063000 0.062333 0.575102 -0.512101 -1.424898 2.518019
63 2018Q1 0.077667 0.063000 1.290761 -1.213094 -0.709239 2.358412
64 2018Q2 0.084333 0.077667 0.676590 -0.592257 -1.323410 2.358412
65 2018Q3 0.077333 0.084333 1.116373 -1.039040 -0.883627 2.358412
66 2018Q4 0.050000 0.077333 0.874537 -0.824537 -1.125463 2.358412
67 2019Q1 0.036667 0.050000 0.301811 -0.265144 -1.698189 1.186341
68 2019Q2 0.049333 0.036667 0.739247 -0.689914 -1.260753 1.186341
69 2019Q3 0.022333 0.049333 0.334560 -0.312227 -1.665440 1.186341
70 2019Q4 0.016000 0.022333 0.500167 -0.484167 -1.499833 1.186341
71 2020Q1 0.016000 0.016000 0.668673 -0.652673 -1.331327 -4.198939
72 2020Q2 -0.041000 0.016000 0.133422 -0.174422 -1.866578 -4.198939
73 2020Q3 -0.061667 -0.041000 0.033344 -0.095011 -1.966656 -4.198939
74 2020Q4 -0.055000 -0.061667 -0.928998 0.873998 -2.928998 -4.198939
75 2021Q1 -0.058333 -0.055000 -0.531385 0.473052 -2.531385 -3.312424
76 2021Q2 -0.067333 -0.058333 -0.732845 0.665511 -2.732845 -3.312424
In [ ]: